From 2f44d250da13dab5d1b5aeab1aef10ef08aaa880 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 17 Dec 2018 14:38:11 +1300 Subject: Add /j flag to :vimgrep shortcut This prevents a jump to the first match, which I usually don't want, at least immediately. --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index f5ffec73..69f63083 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -404,7 +404,7 @@ xmap { (VerticalRegionUpVisual) xmap } (VerticalRegionDownVisual) " \/ types :vimgrep for me ready to enter a search pattern -nnoremap / :vimgrep /\c/ ** +nnoremap / :vimgrep /\c/j ** " \? types :helpgrep for me ready to enter a search pattern nnoremap ? :helpgrep \c -- cgit v1.2.3 From 06dae018ff0b41bc6140a603f5cbf2b54b2fd3ae Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 17 Dec 2018 15:10:18 +1300 Subject: Use `command` consistently, silence ShellCheck ShellCheck (SC2164) is upset about these `cd` commands where the return type isn't being checked, but they're all by design, as they're the last command in the function, and thereby constitute the function's return value implicitly. Otherwise, this commit changes the shrc.d and profile.d subfiles to use the `command` wrapper only where it's actually needed. --- sh/profile.d/options.sh | 4 ++-- sh/shrc.d/bd.sh | 3 ++- sh/shrc.d/gd.sh | 3 ++- sh/shrc.d/gt.sh | 3 ++- sh/shrc.d/mkcd.sh | 5 +++-- sh/shrc.d/pd.sh | 3 ++- sh/shrc.d/rd.sh | 3 ++- sh/shrc.d/scr.sh | 3 ++- sh/shrc.d/sd.sh | 3 ++- sh/shrc.d/ud.sh | 3 ++- sh/shrc.d/vr.sh | 3 ++- 11 files changed, 23 insertions(+), 13 deletions(-) diff --git a/sh/profile.d/options.sh b/sh/profile.d/options.sh index 58376fb3..c60dd140 100644 --- a/sh/profile.d/options.sh +++ b/sh/profile.d/options.sh @@ -13,7 +13,7 @@ options() { [ -d "$dir" ] && return # Create the directory and step into it - command -p mkdir -p -- "$dir" || return + mkdir -p -- "$dir" || return cd -- "$dir" || return # Write the program's --help output to a file, even if it's empty @@ -23,7 +23,7 @@ options() { # Iterate through remaining arguments (desired options), creating files to # show they're available if found in the help output for opt do - command -p grep -q -- \ + command grep -q -- \ '[^[:alnum:]]--'"$opt"'[^[:alnum:]]' help || continue touch -- "$opt" done diff --git a/sh/shrc.d/bd.sh b/sh/shrc.d/bd.sh index 29bde513..a942af6b 100644 --- a/sh/shrc.d/bd.sh +++ b/sh/shrc.d/bd.sh @@ -43,5 +43,6 @@ bd() { fi # We have a match; try and change into it - command cd -- "$1" + # shellcheck disable=SC2164 + cd -- "$1" } diff --git a/sh/shrc.d/gd.sh b/sh/shrc.d/gd.sh index 9f6a43e7..b9af480e 100644 --- a/sh/shrc.d/gd.sh +++ b/sh/shrc.d/gd.sh @@ -14,5 +14,6 @@ gd() { fi # Go to the marked directory - cd -- "$PMD" || return + # shellcheck disable=SC2164 + cd -- "$PMD" } diff --git a/sh/shrc.d/gt.sh b/sh/shrc.d/gt.sh index 7a52571d..193a2996 100644 --- a/sh/shrc.d/gt.sh +++ b/sh/shrc.d/gt.sh @@ -24,5 +24,6 @@ gt() { fi # Try to change into the determined directory, or root if empty - command cd -- "${1:-/}" + # shellcheck disable=SC2164 + cd -- "${1:-/}" } diff --git a/sh/shrc.d/mkcd.sh b/sh/shrc.d/mkcd.sh index cd882b51..bfe8a142 100644 --- a/sh/shrc.d/mkcd.sh +++ b/sh/shrc.d/mkcd.sh @@ -1,5 +1,6 @@ # Create a directory and change into it mkcd() { - command -p mkdir -p -- "$1" || return - command cd -- "$1" + mkdir -p -- "$1" || return + # shellcheck disable=SC2164 + cd -- "$1" } diff --git a/sh/shrc.d/pd.sh b/sh/shrc.d/pd.sh index e3a6daaa..d5257ba5 100644 --- a/sh/shrc.d/pd.sh +++ b/sh/shrc.d/pd.sh @@ -27,5 +27,6 @@ pd() { set -- "${1%/*}" # Try to change into the determined directory, or root if empty - command cd -- "${1:-/}" + # shellcheck disable=SC2164 + cd -- "${1:-/}" } diff --git a/sh/shrc.d/rd.sh b/sh/shrc.d/rd.sh index 9633713a..5fbd5ac5 100644 --- a/sh/shrc.d/rd.sh +++ b/sh/shrc.d/rd.sh @@ -35,5 +35,6 @@ rd() { esac # Try to change into the determined directory - command cd -- "$1" + # shellcheck disable=SC2164 + cd -- "$1" } diff --git a/sh/shrc.d/scr.sh b/sh/shrc.d/scr.sh index 9af8dd74..14a58ad1 100644 --- a/sh/shrc.d/scr.sh +++ b/sh/shrc.d/scr.sh @@ -2,5 +2,6 @@ # files into $HOME, and making the system do cleanup for me. Single optional # argument is the string to use for naming the directory; defaults to "scr". scr() { - cd -- "$(mktd "${1:-scr}")" || return + # shellcheck disable=SC2164 + cd -- "$(mktd "${1:-scr}")" } diff --git a/sh/shrc.d/sd.sh b/sh/shrc.d/sd.sh index 8b12c170..58d1a375 100644 --- a/sh/shrc.d/sd.sh +++ b/sh/shrc.d/sd.sh @@ -113,5 +113,6 @@ sd() { esac # Try and change into the first parameter - command cd -- "$1" + # shellcheck disable=SC2164 + cd -- "$1" } diff --git a/sh/shrc.d/ud.sh b/sh/shrc.d/ud.sh index 06234569..f7f33caf 100644 --- a/sh/shrc.d/ud.sh +++ b/sh/shrc.d/ud.sh @@ -42,5 +42,6 @@ ud() { shift # Try to change into the determined directory, or the root if blank - command cd -- "${1:-/}" + # shellcheck disable=SC2164 + cd -- "${1:-/}" } diff --git a/sh/shrc.d/vr.sh b/sh/shrc.d/vr.sh index c7057ec2..d9cfda62 100644 --- a/sh/shrc.d/vr.sh +++ b/sh/shrc.d/vr.sh @@ -59,5 +59,6 @@ vr() { [ -n "$1" ] || return # Try to change into the determined directory - command cd -- "$@" + # shellcheck disable=SC2164 + cd -- "$@" } -- cgit v1.2.3 From 8e2949fccf42531867196f2b230f59e842ca3505 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 17 Dec 2018 15:13:22 +1300 Subject: Use exec for clearer subshell semantics --- sh/shrc.d/grep.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/shrc.d/grep.sh b/sh/shrc.d/grep.sh index 997babc9..c448c81d 100644 --- a/sh/shrc.d/grep.sh +++ b/sh/shrc.d/grep.sh @@ -15,7 +15,7 @@ grep() { # Add --color=auto if the terminal has at least 8 colors if [ -e "$HOME"/.cache/sh/opt/grep/color ] && - [ "$({ tput colors||tput Co||echo 0; } 2>/dev/null)" -ge 8 ] ; then + [ "$(exec 2>/dev/null;tput colors||tput Co||echo 0)" -ge 8 ] ; then set -- --color=auto "$@" fi -- cgit v1.2.3 From 7828d0f0ff2fc0fb3e2950b7093b7d6d7e62fb85 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 17 Dec 2018 15:13:41 +1300 Subject: Adjust PS1-PS4 reset --- sh/shrc.d/prompt.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sh/shrc.d/prompt.sh b/sh/shrc.d/prompt.sh index 30e4e9d8..cb32c113 100644 --- a/sh/shrc.d/prompt.sh +++ b/sh/shrc.d/prompt.sh @@ -1,8 +1,15 @@ -# Some systems' /etc/profile setups export PS1, which really fouls things up -# when switching between non-login shells; let's put things right by unsetting -# it to break the export and then just setting them as simple variables -unset PS1 PS2 PS3 PS4 -PS1='$ ' PS2='> ' PS3='? ' PS4='+ ' +# Some systems' /etc/profile setups export their prompt strings (PS1, PS2...), +# which really fouls things up when switching between non-login shells; let's +# put things right by unsetting each of them to break the export, and then just +# setting them as simple variables +unset PS1 +PS1='$ ' +unset PS2 +PS2='> ' +unset PS3 +PS3='? ' +unset PS4 +PS4='+ ' # If we have an SSH_CLIENT or SSH_CONNECTION environment variable, put the # hostname in PS1 too. -- cgit v1.2.3 From 8ef8c5ec49d3722888d61084be2f06a9d8a17329 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 17 Dec 2018 15:13:54 +1300 Subject: Follow ShellCheck's recommendation of -z over !-n I think !-n is a little clearer, but -z is OK. --- sh/profile.d/welcome.sh | 2 +- sh/shrc.d/xd.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sh/profile.d/welcome.sh b/sh/profile.d/welcome.sh index cdd41edb..22cdde93 100644 --- a/sh/profile.d/welcome.sh +++ b/sh/profile.d/welcome.sh @@ -20,7 +20,7 @@ esac # Show a fortune if welcome fortune ; then - if ! [ -n "$FORTUNE_PATH"] && + if [ -z "$FORTUNE_PATH" ] && [ -d "$HOME"/.local/share/games/fortunes ] ; then FORTUNE_PATH=$HOME/.local/share/games/fortunes fi diff --git a/sh/shrc.d/xd.sh b/sh/shrc.d/xd.sh index 7c17adea..b26d88b3 100644 --- a/sh/shrc.d/xd.sh +++ b/sh/shrc.d/xd.sh @@ -8,7 +8,7 @@ xd() { fi # Complain if mark not actually set yet - if ! [ -n "$PMD" ] ; then + if [ -z "$PMD" ] ; then printf >&2 'gd(): Mark not set\n' return 1 fi -- cgit v1.2.3 From 57d39d92fad5418e96dd4d69d6e86a578c3764b4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 17 Dec 2018 15:33:37 +1300 Subject: Remove now-unneeded shellcheck disable rules These two comments disabling SC2154 were added in commit 5fa3ef7, because ShellCheck 0.50 did not recognise the NAME pointed to by `read -a NAME` commands as an array assignment. This bug has been corrected in ShellCheck 0.60, meaning that these comments are no longer required. --- bash/bash_completion.d/make.bash | 1 - bash/bash_completion.d/path.bash | 1 - 2 files changed, 2 deletions(-) diff --git a/bash/bash_completion.d/make.bash b/bash/bash_completion.d/make.bash index 909c52fb..b3148ff1 100644 --- a/bash/bash_completion.d/make.bash +++ b/bash/bash_completion.d/make.bash @@ -38,7 +38,6 @@ _make() { < <(printf '%s\n' "${line%%:*}") # Short-circuit if there are no targets - # shellcheck disable=SC2154 ((${#targets[@]})) || exit # Make matches behave correctly diff --git a/bash/bash_completion.d/path.bash b/bash/bash_completion.d/path.bash index c3bb7b80..9224506a 100644 --- a/bash/bash_completion.d/path.bash +++ b/bash/bash_completion.d/path.bash @@ -66,7 +66,6 @@ _path() { < <(printf '%s\0' "$PATH") # Print shell-quoted matching parts, null-terminated - # shellcheck disable=SC2154 for path in "${paths[@]}" ; do case $path in ("$2"*) printf '%q\0' "$path" ;; -- cgit v1.2.3 From 028ebe900329c5bccb5bee445bcee25aec892424 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 19 Dec 2018 11:07:00 +1300 Subject: Add sh.vim mapping to insert '\'' quickly This was added as a Bash Readline macro in commit 25b513d, and has proven to be very useful. I don't normally like insert mode maps in Vim, especially Alt keys, so I'm not sure this will stick; we'll see. --- vim/after/ftplugin/sh.vim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vim/after/ftplugin/sh.vim b/vim/after/ftplugin/sh.vim index 6ee016a5..d6716a3d 100644 --- a/vim/after/ftplugin/sh.vim +++ b/vim/after/ftplugin/sh.vim @@ -45,3 +45,12 @@ nnoremap l \ :compiler shellcheck let b:undo_ftplugin .= '|nunmap c' \ . '|nunmap l' + +" Mapping to insert '\'' with Alt+'; not sure I'll keep this just yet +if has('gui_running') + inoremap '\'' + let b:undo_ftplugin .= '|nunmap ' +else + inoremap ' '\'' + let b:undo_ftplugin .= '|nunmap ''' +endif -- cgit v1.2.3 From 2488fcfddb4e58c9b6fe83bb960283126388695b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 19 Dec 2018 11:11:42 +1300 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 2a431fea..2addfdb6 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v3.2.0 -Fri Dec 14 00:14:00 UTC 2018 +tejr dotfiles v3.3.0 +Tue Dec 18 22:11:42 UTC 2018 -- cgit v1.2.3