From d62f1d1673fc0a319ea4581dee0f6085b1f70005 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Wed, 2 Oct 2019 16:35:18 +0200 Subject: Add shell configs --- .config/shell/functions.d/c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .config/shell/functions.d/c (limited to '.config/shell/functions.d/c') 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 +} -- cgit v1.1