Skip to content

Instantly share code, notes, and snippets.

@ewieberappc
Last active March 29, 2019 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ewieberappc/c9603f7d96b6fb9f7750 to your computer and use it in GitHub Desktop.
Save ewieberappc/c9603f7d96b6fb9f7750 to your computer and use it in GitHub Desktop.
Re-run previous commands with Appc CLI debugging options
USAGE:
$ verbose - Run the previous command with 'DEBUG=*' and '-l trace'
$ verbose <number> - Run the command from <number> commands ago with 'DEBUG=*' and '-l trace'
$ verbose <string> - Run the last command containing <string> with 'DEBUG=*' and '-l trace'
INSTALLATION:
1. Download the executable file to a folder (recommended '~/bin')
2. Add the path to the folder to your PATH in your .bash_profile (export PATH=$PATH:~/bin)
3. Add an alias to your .bash_profile to run the command in the current shell: ( verbose(){ . .verbose $@; } )
4. Restart your terminal or run '. ~/.bash_profile'
NOTES:
I like to rename the executable to '-v' for speed. Its very easy to run a command, such as a build/run command, kill it,
then run '-v' to get all your debugging and output needs
set -o history; vnum=2; if [[ "$1" =~ ^-?[0-9]+$ ]]; then vnum=$((1+$1)); fi; if [[ ! -z "$1" ]] && [[ "$1" == *[a-zA-Z]* ]]; then IN=$( history | grep $1 | tail -2 | head -1 | sed 's/[ 0-9]*//' ); while [[ "$IN" == '-v '"$1" ]]; do vnum+=1; IN=$( history | grep $1 | tail -"$vnum" | head -1 | sed 's/[ 0-9]*//' ); done; if [[ -z "$IN" ]]; then echo -e $'\e[37m'"\tNo command found matching: "$1$'\e[0m'; exit; fi; else IN=$( history | tail -"$vnum" | head -1 | sed 's/[ 0-9]*//' ); fi; if [[ "$IN" == ${FUNCNAME[0]} ]]; then echo 'Cannot repeat: '$IN; exit; fi; IN=${IN/"DEBUG=* "}; IN=${IN/" -l trace"}; echo -e $'\e[37m'"\tRunning: DEBUG=* "$IN" -l trace\n"$'\e[0m'; history -s 'DEBUG=* '$IN' -l trace'; DEBUG=* $IN -l trace;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment