aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IDEAS.markdown1
-rw-r--r--ISSUES.markdown3
-rw-r--r--bash/bash_completion.d/path.bash2
-rw-r--r--sh/profile.d/options.sh17
-rw-r--r--sh/shrc.d/path.sh38
5 files changed, 51 insertions, 10 deletions
diff --git a/IDEAS.markdown b/IDEAS.markdown
index 39d9511e..25b79516 100644
--- a/IDEAS.markdown
+++ b/IDEAS.markdown
@@ -8,5 +8,4 @@ Ideas
manageable
* Have eds(1df) accept stdin with the "starting content" for the script
* Convert all the manual pages to mandoc maybe? <https://en.wikipedia.org/wiki/Mandoc>
-* Add "pop" and "shift" methods to path()
* edio(1df), like vipe(1)
diff --git a/ISSUES.markdown b/ISSUES.markdown
index c2b7f350..e4c4a161 100644
--- a/ISSUES.markdown
+++ b/ISSUES.markdown
@@ -19,3 +19,6 @@ Known issues
* I can't find a clean way of detecting a restricted shell for ksh instances
to prevent trying to load anything fancy (works for Bash)
* Zsh, either! $options[restricted] is "off" within the startup file
+* I'm still not sure that the special character escaping for the ksh prompt
+ actually works. The line-wrapping behaviour for ksh93 seems to be a bit
+ weird. This requires debugging.
diff --git a/bash/bash_completion.d/path.bash b/bash/bash_completion.d/path.bash
index a65e10ce..ba2dcb79 100644
--- a/bash/bash_completion.d/path.bash
+++ b/bash/bash_completion.d/path.bash
@@ -6,7 +6,7 @@ _path() {
# Complete operation as first word
local cmd
- for cmd in list insert append remove check help ; do
+ for cmd in list insert append remove shift pop check help ; do
[[ $cmd == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue
COMPREPLY[${#COMPREPLY[@]}]=$cmd
done
diff --git a/sh/profile.d/options.sh b/sh/profile.d/options.sh
index 345888d0..a668a360 100644
--- a/sh/profile.d/options.sh
+++ b/sh/profile.d/options.sh
@@ -1,10 +1,13 @@
# Cache the options available to certain programs. Run all this in a subshell
# (none of its state needs to endure in the session)
(
-options() (
+options() {
# Check or create the directory to cache the options
+ # Shift the program name off; remaining arguments are the options to check
dir=$HOME/.cache/$1
+ prog=$1
+ shift
# Directory already exists; bail out
[ -d "$dir" ] && exit
@@ -14,18 +17,16 @@ options() (
cd -- "$dir" || exit
# Write the program's --help output to a file, even if it's empty
- "$1" --help </dev/null >help 2>/dev/null || exit
-
- # Shift the program name off; remaining arguments are the options to check
- shift
+ # This probably only works with GNU tools in general
+ "$prog" --help </dev/null >help 2>/dev/null || exit
- # Iterate through some useful options and create files to show they're
- # available if found in the help output
+ # 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 -- '[^[:alnum:]]--'"$opt"'[^[:alnum:]]' help &&
touch -- "$opt"
done
-)
+}
# Cache options for bc(1)
options bc \
diff --git a/sh/shrc.d/path.sh b/sh/shrc.d/path.sh
index 23eec75b..2759e11f 100644
--- a/sh/shrc.d/path.sh
+++ b/sh/shrc.d/path.sh
@@ -79,6 +79,40 @@ path() {
PATH=${PATH%%:}
;;
+ # Remove the first directory in $PATH
+ shift)
+ case $PATH in
+ '')
+ printf >&2 'path(): %s: PATH is empty!\n' "$@"
+ return 1
+ ;;
+ *:*)
+ PATH=${PATH#*:}
+ ;;
+ *)
+ # shellcheck disable=SC2123
+ PATH=
+ ;;
+ esac
+ ;;
+
+ # Remove the last directory in $PATH
+ pop)
+ case $PATH in
+ '')
+ printf >&2 'path(): %s: PATH is empty!\n' "$@"
+ return 1
+ ;;
+ *:*)
+ PATH=${PATH%:*}
+ ;;
+ *)
+ # shellcheck disable=SC2123
+ PATH=
+ ;;
+ esac
+ ;;
+
# Check whether a directory is in PATH
check)
path _argcheck "$@" || return
@@ -103,6 +137,10 @@ USAGE:
Add directory DIR (default $PWD) to the end of PATH
path remove [DIR]
Remove directory DIR (default $PWD) from PATH
+ path shift
+ Remove the first directory from PATH
+ path pop
+ Remove the last directory from PATH
path check [DIR]
Return whether directory DIR (default $PWD) is a component of PATH
path help