aboutsummaryrefslogtreecommitdiff
path: root/.config/shell/functions.d
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2019-10-02 16:35:18 +0200
committerPatrick Spek <p.spek@tyil.nl>2019-10-02 16:35:18 +0200
commitd62f1d1673fc0a319ea4581dee0f6085b1f70005 (patch)
tree78ea262acbdf6b43ed9c7c3f18b8012867e40615 /.config/shell/functions.d
parent06d7914df92c78469b84220aee5e18f2517af1dc (diff)
Add shell configs
Diffstat (limited to '.config/shell/functions.d')
-rw-r--r--.config/shell/functions.d/c50
-rw-r--r--.config/shell/functions.d/m5
-rw-r--r--.config/shell/functions.d/s6
3 files changed, 61 insertions, 0 deletions
diff --git a/.config/shell/functions.d/c b/.config/shell/functions.d/c
new file mode 100644
index 0000000..bc1c033
--- /dev/null
+++ b/.config/shell/functions.d/c
@@ -0,0 +1,50 @@
+#!/usr/bin/env sh
+
+c()
+{
+ destination="$1"
+
+ if [ -z "${SHELLSTORE}" ]
+ then
+ return 1
+ fi
+
+ store=${SHELLSTORE}/chdir_history
+
+ # Make sure the store exists
+ touch "${store}"
+
+ if [ -z "$1" ]
+ then
+ destination=$(tail -n 1 "${store}")
+
+ if [ "${destination}" != "" ]
+ then
+ sed '$ d' "${store}" > "${store}.sed"
+ mv "${store}.sed" "${store}"
+ fi
+ else
+ dots=$(expr "${destination}" : '^\.\+$')
+
+ if [ "$dots" -gt 2 ]
+ then
+ destination=""
+
+ while [ "${dots}" -gt 1 ]
+ do
+ destination="${destination}../"
+
+ dots=$((dots - 1))
+ done
+ fi
+ fi
+
+ owd=$(pwd)
+
+ cd "${destination}" || return 2
+ l
+
+ [ ! -z "$1" ] && printf "%s\n" "${owd}" >> "${store}"
+
+ unset destination dots store
+}
diff --git a/.config/shell/functions.d/m b/.config/shell/functions.d/m
new file mode 100644
index 0000000..75a2095
--- /dev/null
+++ b/.config/shell/functions.d/m
@@ -0,0 +1,5 @@
+#!/usr/bin/env sh
+
+m () {
+ mkdir -p "$1" && c "$1"
+}
diff --git a/.config/shell/functions.d/s b/.config/shell/functions.d/s
new file mode 100644
index 0000000..bce5780
--- /dev/null
+++ b/.config/shell/functions.d/s
@@ -0,0 +1,6 @@
+#!/usr/bin/env sh
+
+s()
+{
+ sed -n "$1"
+}