scripts/misc/re
2020-04-02 10:38:36 +02:00

41 lines
857 B
Bash
Executable file

#!/bin/zsh
SCRIPTDIR=$XDG_CONFIG_HOME/re/
zparseopts -D h=help -help=help d:=dir -dir:=dir n=dry_run -dry-run=dry_run e=edit -edit=edit
if [[ -z "$@" || -n $help ]]; then
<<-HELP
re - execute regular jobs without cluttering your path
Usage: re [opts] <scriptname> [scriptopts]
1. put script in $SCRIPTDIR
2. run "re <scriptname>"
3. ...
4. PROFIT!
Options:
-d, --dir=DIR change to given directory
-n, --dry-run just display the script, that would be executed
-e, --edit open the script in an editor
HELP
exit
fi
if [[ -n $dir ]]; then
cd $dir[2]
fi
if [[ -e $SCRIPTDIR/$1 ]]; then
if [[ -n $dry_run ]]; then
${PAGER:-less} -F $SCRIPTDIR/$1
elif [[ -n $edit ]]; then
${EDITOR:-vim} $SCRIPTDIR/$1
else
script=$1
shift
. $SCRIPTDIR/$script "$@"
fi
else
echo "Script \"$1\" not found"
fi