Skip to content

Instantly share code, notes, and snippets.

@listenlight
Created June 24, 2021 11:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save listenlight/89649ee0d9f39f10b99a38f2e7d9912c to your computer and use it in GitHub Desktop.
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
#!/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'
@listenlight
Copy link
Author

add_alias_to_bash_aliases_real_time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment