DEV Community


Posted on

Bash Alias and Functions

Hello dev people.

When I started working in a Web Dev industry one of the first thing to learn was to setup shortcuts/alias and automate tasks.

Nobody wants to type repetitive tasks and build full starter packages every time the project starts.

This is where working with terminal commands and using functions and alias is beneficial, speeds up the work process and avoids repetitive typing.

I will be editing this post from time to time whenever I have something worth sharing.

Setup your first bash alias commands

  • win users install git bash, supports mac, but mac users have terminal which works just fine
  • open up ~/.bash_profile with your code editor or with nano,vim etc.
  • see examples for the alias command below
  • once you have finished with the ~/.bash_profile make sure to run the source ~/.bash_profile . Syntax errors should show up here if any

## Git commands

alias gs='git status'
alias gb='git branch'
alias commit='git commit -m "simple update"'
alias gpush='git push origin master'
# Copy SSH public key
alias sshcopy='clip < ~/.ssh/ && echo "~/.ssh/ Copied to clipboard"'
alias sshkey="cat ~/.ssh/ | pbcopy && echo 'Copied to Clipboard.'"

## Tasks

alias cd..='cd ../'
alias cd2='cd ../../'
alias ll='ls -lha'
alias cls='clear'
alias eval='eval $\(ssh-agent -s\)'

# Start the Wamp Manager
alias wamp='start /f/wamp64/wampmanager.exe'

# MySQL Import/Export
alias slqdump='mysqldump -uroot -p mydatabasename'
alias slqimport='mysql -uroot -p mydatabasename < db/import.sql'

## Tar export with gz command for import/export

### make dir and then export tar into that
alias tarexport='echo provide 2 params, 1 is the tar file and 2 is the dir where tar will be exported'
function tarexport() { mkdir "$2" && tar -xvf "$1" -C "$2"; }

## TAR compress

alias tarmake='echo provide 2 params, 1 is the tar filename \(with gz\) and 2 param is what will be compressed into tar.gz'
function tarmake() { tar -czvf "$1" "$2"; }

Enter fullscreen mode Exit fullscreen mode

Top comments (0)