From 70543fc1ef9733fb754cecda96805349cb36de32 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 21 Dec 2024 15:13:05 -0400 Subject: Add shebangs and x bit to executables With run.sh, we can build and run the file in one go. This means we can also use it as an interpreter in a shebang line and properly use the Unix executable bit. This is pretty cool and gives a few advantages: running any executable file is just `exec file.hs` or even `./file.hs`, finding all executables is `fd -t x`, you don't need to specify or know an `out` name to run something, execution of a program is standardized. There is a hack to get this to work. In C and Common Lisp, `#!` is illegal syntax, so I had to use shell syntax to invoke run.sh, call it on the current file, and then exit the shell script. Meanwhile, run.sh takes the file and evals the whole thing, building and running it. As long as either `//` or `;` is a comment character in the target language, then this works. Maybe a better thing to do would be to pre-process the file and remove the `#!` before passing it to the C compiler, like [ryanmjacobs/c][1] and [tcc][2]? However this won't work in Lisp because then I can't just load the file directly into the repl, so maybe the comment hack needs to stay. [1]: https://github.com/ryanmjacobs/c/tree/master [2]: https://repo.or.cz/tinycc.git/blob/HEAD:/tccrun.c --- Omni/Ide/hooks/post-applypatch | 2 +- Omni/Ide/hooks/post-commit | 2 +- Omni/Ide/hooks/post-rewrite | 2 +- Omni/Ide/hooks/pre-auto-gc | 2 +- Omni/Ide/hooks/reference-transaction | 2 +- Omni/Ide/ns.sh | 1 + Omni/Ide/run.sh | 1 + 7 files changed, 7 insertions(+), 5 deletions(-) (limited to 'Omni/Ide') diff --git a/Omni/Ide/hooks/post-applypatch b/Omni/Ide/hooks/post-applypatch index 5071dc5..4919e84 100755 --- a/Omni/Ide/hooks/post-applypatch +++ b/Omni/Ide/hooks/post-applypatch @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash ## START BRANCHLESS CONFIG git branchless hook post-applypatch "$@" diff --git a/Omni/Ide/hooks/post-commit b/Omni/Ide/hooks/post-commit index cd1f195..bdccee3 100755 --- a/Omni/Ide/hooks/post-commit +++ b/Omni/Ide/hooks/post-commit @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash ## START BRANCHLESS CONFIG git branchless hook post-commit "$@" diff --git a/Omni/Ide/hooks/post-rewrite b/Omni/Ide/hooks/post-rewrite index 8b3237a..711cc0c 100755 --- a/Omni/Ide/hooks/post-rewrite +++ b/Omni/Ide/hooks/post-rewrite @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash ## START BRANCHLESS CONFIG git branchless hook post-rewrite "$@" diff --git a/Omni/Ide/hooks/pre-auto-gc b/Omni/Ide/hooks/pre-auto-gc index c92a844..30d4a44 100755 --- a/Omni/Ide/hooks/pre-auto-gc +++ b/Omni/Ide/hooks/pre-auto-gc @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash ## START BRANCHLESS CONFIG git branchless hook pre-auto-gc "$@" diff --git a/Omni/Ide/hooks/reference-transaction b/Omni/Ide/hooks/reference-transaction index ea0cce6..474e52d 100755 --- a/Omni/Ide/hooks/reference-transaction +++ b/Omni/Ide/hooks/reference-transaction @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash ## START BRANCHLESS CONFIG # Avoid canceling the reference transaction in the case that `branchless` fails diff --git a/Omni/Ide/ns.sh b/Omni/Ide/ns.sh index a56ed89..cddb35a 100755 --- a/Omni/Ide/ns.sh +++ b/Omni/Ide/ns.sh @@ -27,6 +27,7 @@ fzf_flags=( --bind "alt-enter:execute(repl.sh --bash {})" --bind "ctrl-space:execute(ship.sh {} ; read -p [fin])" --bind "alt-t:execute(bild {} ; run.sh {} test ; read -p [fin])" + --bind "alt-e:execute({} ; read -p [fin])" --bind "ctrl-/:change-preview-window(right,88|right,70%|hidden|)" --bind "alt-0:change-preview(bat -p --color=always {})" --bind "alt-1:change-preview(git log --color=always --date=relative --abbrev-commit --pretty=format:'%Cred%h%Creset %s / %an %Creset%C(yellow)%d%Creset%Cgreen(%cr)%Creset' -- {})" diff --git a/Omni/Ide/run.sh b/Omni/Ide/run.sh index 506aa92..e300fcc 100755 --- a/Omni/Ide/run.sh +++ b/Omni/Ide/run.sh @@ -3,4 +3,5 @@ set -eu target=$1 shift out=$(bild --plan "$target" | jq --raw-output ".\"${target}\".out") +[[ -f "$out" ]] || bild "$target" exec "${CODEROOT:?}/_/bin/$out" "$@" -- cgit v1.2.3