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.
This commit is contained in:
Sheldon Lee 2022-06-18 19:48:34 +08:00
parent 9ae8541b92
commit 4feed1672f
2 changed files with 36 additions and 0 deletions

View File

@ -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

View File

@ -99,3 +99,30 @@ tzathura()
fi
zathura "$@" -e $(</tmp/tabbed.xid) & disown
}
wdir()
{
wdir="$PWD/$1"
[ -d "$wdir" ] && echo "$wdir" > "$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
}