option to edit dotfile#1
Conversation
creiber
commented
Jun 25, 2020
- option to edit dotfile
- no error message when called without args
- option to edit dotfile - no error message when called without args
rse
left a comment
There was a problem hiding this comment.
Thanks for your contribution, Christian! See below for my comments.
| echo " dotfiles -e [<file>...]" 1>&2 | ||
| } | ||
| if [ $# -eq 0 ]; then | ||
| echo "dotfiles: ERROR: invalid number of arguments" 1>&2 |
There was a problem hiding this comment.
Why are you removing this line? It seems to be not unrelated to the new -e options.
There was a problem hiding this comment.
This is true but IMHO shell tools are expected to emit their usage either when called without arguments or when called with an explicit –h or –help option. One of those should work and is not an error. It is just the user asking for advice how to use the tool. YMMV.
| # command-line argument parsing | ||
| usage () { | ||
| echo "dotfiles: USAGE: dotfiles [-v|--version] [-q|--quiet] [-f|--force] [-p|--preserve] [-r|--remote <user>@<host>] <home-directory>" 1>&2 | ||
| echo " dotfiles -e [<file>...]" 1>&2 |
There was a problem hiding this comment.
Here you should write -e|--edit to also show the long-option alias.
| -q|--quiet ) quiet=yes; shift ;; | ||
| -f|--force ) force=yes; shift ;; | ||
| -p|--preserve ) preserve=yes; shift ;; | ||
| -e|--edit ) edit=yes; shift ;; |
There was a problem hiding this comment.
You should pre-initialize the variable edit beforehand similar to what is done for the other options.
| fi | ||
| if [ $edit = yes ]; then | ||
| cd $HOME/.dotfiles | ||
| exec ${EDITOR:-vi} ${*:-.} |
There was a problem hiding this comment.
Not all $EDITORs might support editing a directory .. This then would fail here...
There was a problem hiding this comment.
Correct. The user is free to either provide a capable editor in $EDITOR or to explicitely name the file he or she wants to edit. If they refuse to provide the prereqs they won’t receive the benefits. That's something to be documented but I would not miss the fine feature of directory selection as most editors in use today (and preinstalled) can do it.
| fi | ||
| if [ $# -ne 1 ]; then | ||
| echo "dotfiles: ERROR: invalid number of arguments" 1>&2 | ||
| echo "dotfiles: ERROR: invalid number of arguments $#" 1>&2 |
There was a problem hiding this comment.
It's OK to print the number of actually provided arguments, but (a) it doesn't read nicely when you see "invalid number of arguments 7" and (b) the actual number of expected arguments could be more useful in the output. Perhaps a better error could be "invalid number of arguments (expected 1 argument, received N arguments)".