dotfiles/.config/scripts/functions/wdir
Sheldon Lee d9405c5166 Split .custom_bash_scripts into a multiple files.
The files are in ~/.config/scripts/functions.
2022-06-26 08:43:03 +08:00

39 lines
768 B
Bash

#!/bin/bash
#
# This is a collection of functions that manages a file /tmp as defined by
# $WDIR_PATH set in .bashrc. They basicaly manage a 'working directory', which
# the path of is stored in said file in /tmp.
#
# The .bashrc reads the path to the directory from the file and cd's into it
# when a new shell is created.
# Set the working directory.
wdir()
{
wdir="$PWD/$1"
[ -d "$wdir" ] && echo "$wdir" > "$WDIR_PATH" && echo "set $wdir"
}
# Print the workind directory.
pwdir()
{
if [ -f "$WDIR_PATH" ]
then
cat "$WDIR_PATH"
else
echo "Working directory not set."
fi
}
# Clear the workind directory.
cwdir()
{
if [ -f "$WDIR_PATH" ]
then
rm -f "$WDIR_PATH"
echo "Cleared working directory."
else
echo "Working directory not set."
fi
}