Skip to content

Instantly share code, notes, and snippets.

@jaqque
Created September 20, 2016 20:55
Show Gist options
  • Save jaqque/3e8629916dd951bfb971731bb7cd80a9 to your computer and use it in GitHub Desktop.
Save jaqque/3e8629916dd951bfb971731bb7cd80a9 to your computer and use it in GitHub Desktop.
#!/bin/zsh
# John H. Robinson, IV <[email protected]>
# 2016-09-20
MYNAME=${0##*/}
s='/'; # full-width solidus U+FF0F <http://www.fileformat.info/info/unicode/char/ff0f/>
help() {
rmate --help | sed s/rmate/$MYNAME/
}
while [[ $@ ]]; do
case $1 in
-H|--host) ;&
-p|--port) ;&
-l|--line) ;&
-m|--name) ;&
-t|--type) args=($args $1 $2); shift ;;
-w|--wait) ;&
--no-wait) ;&
-n|--new) ;&
-f|--force) ;&
-v|--verbose) ;&
--version) args=($args $1) ;;
-h|--help) help; exit ;;
*) files=($files $1) ;;
esac
shift
done
for file in $files; do
# path/to/updir/dirname/filename
filename=${file##*/}
dirname=${${file%/*}##*/}
updir=${${file%/*/*}##*/}
toppwd=${PWD##*/}
case $file in
roles/*/*/*|*/roles/*/*/*)
rmate $args --name $updir$s$dirname$s$filename $file ;;
*/main.yml)
rmate $args --name $dirname$s$filename $file ;;
main.yml)
rmate $args --name $toppwd$s$filename $file ;;
*)
rmate $args $file ;;
esac
done
# TODO:
# [X] 1) open multiple files
# [X] 2) re-order things so when calling rmate, the file is always last
# [ ] 3) when specifying a directory, open all **/*.yml files
# [X] 4) if one of the dirs is "roles" make the name project-section.yml
# eg: roles/USTreasury/defaults/main.yml -> USTreasury-defaults.yml
# [X] 5) if the dirs is roles, and the file isn't main.yml, still use the above naming
# eg: roles/USTreasury/defaults/OSX.yml -> USTreasury-defaults-OSX.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment