aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash')
-rw-r--r--bash/bash_completion.d/_ssh_config_hosts.bash43
-rw-r--r--bash/bash_completion.d/git.bash41
-rw-r--r--bash/bash_completion.d/gpg.bash13
-rw-r--r--bash/bash_completion.d/make.bash2
-rw-r--r--bash/bash_completion.d/man.bash1
-rw-r--r--bash/bash_completion.d/mex.bash2
-rw-r--r--bash/bash_completion.d/openssl.bash29
-rw-r--r--bash/bash_completion.d/pass.bash2
-rw-r--r--bash/bash_completion.d/path.bash2
-rw-r--r--bash/bashrc2
-rw-r--r--bash/bashrc.d/keep.bash2
-rw-r--r--bash/bashrc.d/vared.bash2
12 files changed, 82 insertions, 59 deletions
diff --git a/bash/bash_completion.d/_ssh_config_hosts.bash b/bash/bash_completion.d/_ssh_config_hosts.bash
index 3f937a2a..0959f52b 100644
--- a/bash/bash_completion.d/_ssh_config_hosts.bash
+++ b/bash/bash_completion.d/_ssh_config_hosts.bash
@@ -1,31 +1,26 @@
# Complete ssh_config(5) hostnames
_ssh_config_hosts() {
- # Iterate through words from a subshell
- local ci comp
- while read -r comp ; do
- COMPREPLY[ci++]=$comp
- done < <(
+ # Iterate through SSH client config paths
+ local config
+ for config in "$HOME"/.ssh/config /etc/ssh/ssh_config ; do
+ [[ -e $config ]] || continue
- # Iterate through SSH client config paths
- for config in "$HOME"/.ssh/config /etc/ssh/ssh_config ; do
- [[ -e $config ]] || continue
+ # Read 'Host' options and their first value from file
+ local option value ci
+ while read -r option value _ ; do
+ [[ $option == Host ]] || continue
- # Read 'Host' options and their first value from file
- while read -r option value _ ; do
- [[ $option == Host ]] || continue
+ # Check host value
+ case $value in
+ # No empties
+ '') ;;
+ # No wildcards
+ *'*'*) ;;
+ # Found a match; print it
+ "$2"*) COMPREPLY[ci++]=$value ;;
+ esac
- # Check host value
- case $value in
- # No empties
- ('') ;;
- # No wildcards
- (*'*'*) ;;
- # Found a match; print it
- ("$2"*) printf '%s\n' "$value" ;;
- esac
-
- done < "$config"
- done
- )
+ done < "$config"
+ done
}
diff --git a/bash/bash_completion.d/git.bash b/bash/bash_completion.d/git.bash
new file mode 100644
index 00000000..c3a4d49c
--- /dev/null
+++ b/bash/bash_completion.d/git.bash
@@ -0,0 +1,41 @@
+# Complete Git with branch names or tag names if specific keys are used, but
+# fall back on filenames otherwise; it's too complicated to be worth trying to
+# do it all contextually
+
+# Requires Bash >=4.0 for COMP_KEY
+((BASH_VERSINFO[0] >= 4)) || return
+
+# Define and set helper function
+_git() {
+
+ # What completion to do
+ case $COMP_KEY in
+
+ # Complete with branch names if C-x,B is pressed
+ 98)
+ local ci
+ while read -r _ ref ; do
+ branch=${ref#refs/heads/}
+ case $branch in
+ "$2"*) COMPREPLY[ci++]=$branch ;;
+ esac
+ done < <(git show-ref --heads)
+ ;;
+
+ # Complete with tag names if C-x,T is pressed
+ 116)
+ local ci
+ while read -r _ ref ; do
+ tag=${ref#refs/tags/}
+ case $tag in
+ "$2"*) COMPREPLY[ci++]=$tag ;;
+ esac
+ done < <(git show-ref --tags)
+ ;;
+
+ # Do no completion, so we fall back on filenames
+ *) return 1 ;;
+
+ esac
+}
+complete -F _git -o bashdefault -o default git
diff --git a/bash/bash_completion.d/gpg.bash b/bash/bash_completion.d/gpg.bash
index c6f92676..5a055352 100644
--- a/bash/bash_completion.d/gpg.bash
+++ b/bash/bash_completion.d/gpg.bash
@@ -13,14 +13,9 @@ _gpg() {
# Generate completion reply from gpg(1) options
local ci comp
while read -r comp ; do
- COMPREPLY[ci++]=$comp
- done < <(
- gpg --dump-options 2>/dev/null |
- while read -r option ; do
- case $option in
- ("$2"*) printf '%s\n' "$option" ;;
- esac
- done
- )
+ case $comp in
+ "$2"*) COMPREPLY[ci++]=$comp ;;
+ esac
+ done < <(gpg --dump-options 2>/dev/null)
}
complete -F _gpg -o bashdefault -o default gpg
diff --git a/bash/bash_completion.d/make.bash b/bash/bash_completion.d/make.bash
index 7f8b8125..909c52fb 100644
--- a/bash/bash_completion.d/make.bash
+++ b/bash/bash_completion.d/make.bash
@@ -34,11 +34,11 @@ _make() {
esac
# Break the target up with space delimiters
- declare -a targets
IFS=' ' read -a targets -r \
< <(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/man.bash b/bash/bash_completion.d/man.bash
index 50ab852e..714fa493 100644
--- a/bash/bash_completion.d/man.bash
+++ b/bash/bash_completion.d/man.bash
@@ -56,7 +56,6 @@ _man() {
fi
# Add pages from each manual directory
- local pages pi
for mp in "${manpaths[@]}" ; do
[[ -n $mp ]] || continue
diff --git a/bash/bash_completion.d/mex.bash b/bash/bash_completion.d/mex.bash
index b1e0e1a7..d9604b2c 100644
--- a/bash/bash_completion.d/mex.bash
+++ b/bash/bash_completion.d/mex.bash
@@ -51,4 +51,4 @@ _mex() {
done
)
}
-complete -F _mex mex
+complete -F _mex -o filenames mex
diff --git a/bash/bash_completion.d/openssl.bash b/bash/bash_completion.d/openssl.bash
index 1cb4bd07..1e2a9c58 100644
--- a/bash/bash_completion.d/openssl.bash
+++ b/bash/bash_completion.d/openssl.bash
@@ -8,25 +8,18 @@ _openssl() {
((COMP_CWORD == 1)) || return
# Iterate through completions produced by subshell
- local ci comp
- while read -r comp ; do
- COMPREPLY[ci++]=$comp
+ local -a subcmds
+ local ci subcmd
+ while read -a subcmds -r ; do
+ for subcmd in "${subcmds[@]}" ; do
+ case $subcmd in
+ "$2"*) COMPREPLY[ci++]=$subcmd ;;
+ esac
+ done
done < <(
-
- # Run each of the command-listing commands; read each line into an
- # array of subcommands (they are printed as a table)
- for list in commands digest-commands cipher-commands ; do
- openssl list -"$list"
- done | {
- declare -a subcmds
- while read -a subcmds -r ; do
- for subcmd in "${subcmds[@]}" ; do
- case $subcmd in
- ("$2"*) printf '%s\n' "$subcmd" ;;
- esac
- done
- done
- }
+ openssl list -commands \
+ -cipher-commands \
+ -digest-commands
)
}
complete -F _openssl -o bashdefault -o default openssl
diff --git a/bash/bash_completion.d/pass.bash b/bash/bash_completion.d/pass.bash
index 5a6e0b6c..760e774e 100644
--- a/bash/bash_completion.d/pass.bash
+++ b/bash/bash_completion.d/pass.bash
@@ -30,7 +30,7 @@ _pass() {
# Try to iterate into subdirs, use depth search with ** if available
if shopt -s globstar 2>/dev/null ; then
- for entry in "$pass_dir"/"$2"**/*.gpg ; do
+ for entry in "$pass_dir"/"$2"*/**/*.gpg ; do
entries[ei++]=$entry
done
else
diff --git a/bash/bash_completion.d/path.bash b/bash/bash_completion.d/path.bash
index 9234f132..c3bb7b80 100644
--- a/bash/bash_completion.d/path.bash
+++ b/bash/bash_completion.d/path.bash
@@ -62,11 +62,11 @@ _path() {
fi
# Break PATH into parts
- declare -a paths
IFS=: read -a paths -d '' -r \
< <(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" ;;
diff --git a/bash/bashrc b/bash/bashrc
index a05526f2..0400e41d 100644
--- a/bash/bashrc
+++ b/bash/bashrc
@@ -6,7 +6,7 @@ esac
# Don't do anything if restricted, not even sourcing the ENV file
# Testing $- for "r" doesn't work
-! shopt -q restricted_shell >/dev/null 2>&1 || return
+! shopt -q restricted_shell 2>/dev/null || return
# Clear away all aliases; we do this here rather than in the $ENV file shared
# between POSIX shells, because ksh relies on aliases to implement certain
diff --git a/bash/bashrc.d/keep.bash b/bash/bashrc.d/keep.bash
index 48196aeb..191dac4b 100644
--- a/bash/bashrc.d/keep.bash
+++ b/bash/bashrc.d/keep.bash
@@ -83,7 +83,7 @@ EOF
# Iterate through the NAMEs given
local name
- for name ; do
+ for name do
# Check NAMEs for validity
case $name in
diff --git a/bash/bashrc.d/vared.bash b/bash/bashrc.d/vared.bash
index e024f48a..491e5bff 100644
--- a/bash/bashrc.d/vared.bash
+++ b/bash/bashrc.d/vared.bash
@@ -24,7 +24,7 @@ vared() {
return 2
fi
local name
- for name ; do
+ for name do
IFS= read -e -i "${!name}" -p "${prompt:-"$name"=}" -r -- "${name?}"
done
}