Created
May 23, 2020 13:25
-
-
Save anroopak/ae829b49242e3f358bced4326962ee15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARGS_TEXT=""" | |
Usage: mkcdaliases {folder alias name} {folder to reach} | |
Eg: mkcdaliases myfolder ./my-folder | |
This creates a command -> cdmyfolder which navigates to my-folder | |
""" | |
_mkcdaliases() { | |
folder_alias=$1 | |
folder=$2 | |
if ([ -z "$folder_alias" ] || [ -z "$folder" ]) | |
then echo "Invalid args. $ARGS_TEXT" | |
else | |
fullpath=$(realpath $2) | |
no_of_occurrences=$(cat ~/.cdaliases | egrep "cd$folder_alias=" | wc -l) | |
echo "No of Occu: $no_of_occurrences" | |
if [[ "$no_of_occurrences" -eq 1 ]] | |
then | |
sed -i "/alias cd$folder_alias=/c\alias cd$folder_alias=\"cd ${fullpath}\"" ~/.cdaliases | |
else | |
echo "alias cd$folder_alias=\"cd ${fullpath}\"" >> ~/.cdaliases | |
fi | |
fi | |
} | |
alias mkcdaliases="_mkcdaliases" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment