From 4feed1672f09b613dbb83cdc4c7c38bfbcd97600 Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Sat, 18 Jun 2022 19:48:34 +0800 Subject: [PATCH] Added function to set working directory. If a working directory is set with wdir(), bashrc will cd into the path stored in a file written in /tmp. A new terminal will then have a shell in that directory. cwdir() deletes the file in /tmp and pwdir() prints the working directory from said file if it exists. --- .bashrc | 9 +++++++++ .custom_bash_scripts | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/.bashrc b/.bashrc index dee11ca..e2ca0d4 100644 --- a/.bashrc +++ b/.bashrc @@ -35,6 +35,9 @@ if grep "arch-laptop" /etc/hostname &> /dev/null ; then export IS_LAPTOP=1 fi +# Path to store working directory +export WDIR_PATH="/tmp/$(id -u).wdir" + # include bash aliases if [ -f ~/.bash_aliases ] then @@ -53,3 +56,9 @@ then source ~/.nnn_bookmarks fi +if [ -f $WDIR_PATH ] +then + wdir="$(cat $WDIR_PATH)" + echo "Working directory from $WDIR_PATH" + cd "$wdir" +fi diff --git a/.custom_bash_scripts b/.custom_bash_scripts index 7bb7f02..c09e4a6 100644 --- a/.custom_bash_scripts +++ b/.custom_bash_scripts @@ -99,3 +99,30 @@ tzathura() fi zathura "$@" -e $( "$WDIR_PATH" && echo "set $wdir" +} + +pwdir() +{ + if [ -f "$WDIR_PATH" ] + then + cat "$WDIR_PATH" + else + echo "Working directory not set." + fi +} + +cwdir() +{ + if [ -f "$WDIR_PATH" ] + then + rm -f "$WDIR_PATH" + echo "Cleared working directory." + else + echo "Working directory not set." + fi +}