Created
June 24, 2021 11:22
-
-
Save listenlight/89649ee0d9f39f10b99a38f2e7d9912c to your computer and use it in GitHub Desktop.
bash function to add aliases just-in-time and reload the .bash_aliases file
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
#!/bin/bash | |
# add alias definitions on the go, | |
# and reload .bash_aliases into your current shell | |
function addalias() { | |
read -p "alias name: " alias_name | |
read -p "alias cmd: " alias_cmd | |
cmd_str="alias $alias_name=\"$alias_cmd\"" | |
the_rest=" >> ~/.bash_aliases && . ~/.bash_aliases" | |
echo "echo \""$cmd_str""$the_rest"\"" | |
confirm="Y" | |
read -p " is that ok? (y/N): " confirm | |
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then | |
echo $cmd_str >> ~/.bash_aliases && . ~/.bash_aliases | |
echo "neat" | |
fi | |
} | |
alias aa='addalias' |
Author
listenlight
commented
Jun 24, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment