diff options
-rw-r--r-- | README.md | 26 | ||||
-rw-r--r-- | dirstack.sh | 20 | ||||
-rw-r--r-- | history.sh | 3 | ||||
-rw-r--r-- | shell.sh | 20 |
4 files changed, 69 insertions, 0 deletions
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() { + . "$@" +} |