Skip to content

Instantly share code, notes, and snippets.

@pimeo
Last active May 30, 2017 21:55
Show Gist options
  • Save pimeo/f7257db45366d38b428e to your computer and use it in GitHub Desktop.
Save pimeo/f7257db45366d38b428e to your computer and use it in GitHub Desktop.
command to add dynamic alias

README

    1. Create ez-alias.sh file
    1. Add directory of the ez-alias script file to export PATH (ex: export PATH=:/$HOME/BASH)
    1. Add the command source $HOME/BASH/aliases.sh to $HOME/.bash_profile file and source it
    1. Go to any directory and launch command ez-alias.sh and type in the name of your alias then reboot the terminal
  • Done !
#!/bin/bash
# file: $HOME/BASH/aliases.sh
# description: contains all directory aliases
#!/usr/bin/env bash
#file: ez-alias.sh
# directory of the bash script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# directory where the bash script is called
ALIAS_DIR=$(pwd)
echo "Name of the alias: "
read aliasName
# save alias into bash file
echo "alias ez-$aliasName=\"cd $ALIAS_DIR\"" >> "$HOME"/Bash/ez-alias/aliases.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment