-
-
Save jaqque/3e8629916dd951bfb971731bb7cd80a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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