From c0a7566a2025479e906a539d2c1bca9022efc2c8 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 18 Feb 2020 16:13:41 -0500 Subject: initial version --- README.md | 26 ++++++++++++++++++++++++++ dirstack.sh | 20 ++++++++++++++++++++ history.sh | 3 +++ shell.sh | 20 ++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 README.md create mode 100644 dirstack.sh create mode 100644 history.sh create mode 100644 shell.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..55dc9e3 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +This is a collection of shell functions that can give any POSIX shell some +of Bash's extra functionality. The functions are split into groups of related +functionality. To install them into your shell, use the `.` command to read +the appropriate script (e.g. to load `shell.sh`, run `. ./shell.sh`). + +`shell.sh` +---------- +Functionality related to the operation of the shell itself. + +- `suspend` - Suspends a non-login shell. +- `logout` - Exits a login shell. +- `source` - Alternative spelling of `.`. + +`dirstack.sh` +------------- +Functionality for maintaining a stack of working directories. + +- `pushd` - Enter a new directory and add the previous to the stack. +- `popd` - Pop the top directory from the stack and change to it. +- `dirs` - Print out the current directory stack. + +`history.sh` +------------ +Funcionality related to command line history. + +- `history` - Lists the current command history. diff --git a/dirstack.sh b/dirstack.sh new file mode 100644 index 0000000..37c3bf3 --- /dev/null +++ b/dirstack.sh @@ -0,0 +1,20 @@ +pushd() { + _topush=$(pwd) + cd "${1+"$@"}" && _DIRSTACK="$(printf '%s\n' ${_topush} ${_DIRSTACK})" + unset _topush +} + +popd() { + if [ -z "${_DIRSTACK}" ]; then + printf 'popd: directory stack is empty\n' + return 1 + fi + + cd $(dirs | head -n1) + pwd + _DIRSTACK="$(dirs | tail +2)" +} + +dirs() { + printf '%s\n' ${_DIRSTACK} +} diff --git a/history.sh b/history.sh new file mode 100644 index 0000000..ce2d87f --- /dev/null +++ b/history.sh @@ -0,0 +1,3 @@ +history() { + fc -l +} diff --git a/shell.sh b/shell.sh new file mode 100644 index 0000000..45cf5cf --- /dev/null +++ b/shell.sh @@ -0,0 +1,20 @@ +suspend() { + if [ x"$0" -ne x"${0#-}" ]; then + #TODO: handle -f + printf 'suspend: not suspending login shell\n' >&2 + else + kill -STOP $$ + fi +} + +logout() { + if [ x"$0" -ne x"${0#-}" ]; then + printf 'logout: use exit to leave non-login shell\n' >&2 + else + exit "$@" + fi +} + +source() { + . "$@" +} -- cgit v1.2.1