Skip to content

Instantly share code, notes, and snippets.

@BrunIF
Last active July 10, 2020 08:10
Show Gist options
  • Save BrunIF/5c5daad531323ef6ca1a3d304bad11da to your computer and use it in GitHub Desktop.
Save BrunIF/5c5daad531323ef6ca1a3d304bad11da to your computer and use it in GitHub Desktop.
Own shell example
shell() {
TOPCMD=$@ bash -c 'while read -p "${TOPCMD##*/}> " -ra sub; do
case ${sub[0]:-} in
"") continue;;
exit) exit;;
escape) (set -x; ${sub[@]:1});;
*) (set -x; ${TOPCMD} ${sub[@]});;
esac
done'
}
use_prefix () {
while read -p "$* >" -ra c; do
[ "${c[0]}" = "exit" ] && break
"$@" "${c[@]}"
done
}
# not working in MacOS
# All example from https://unix.stackexchange.com/questions/555622/prefix-all-commands-in-shell
use_prefix () {
while read -r c; do
"$@" "${c[@]}"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment