summaryrefslogtreecommitdiff
path: root/dirstack.sh
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-02-18 16:13:41 -0500
committerJakob Kaivo <jkk@ung.org>2020-02-18 16:13:41 -0500
commitc0a7566a2025479e906a539d2c1bca9022efc2c8 (patch)
tree6aabbfb8f5e9657866be5bc5fed3edfdaa20ff26 /dirstack.sh
parent7d700a9f35ff6a870f550236a63d0a08b40e556d (diff)
initial versionHEADmaster
Diffstat (limited to 'dirstack.sh')
-rw-r--r--dirstack.sh20
1 files changed, 20 insertions, 0 deletions
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}
+}