Wednesday, July 12, 2017

Disabling Some Argument In Shell Command (Linux)

To disable any shell command's argument, all you need to do is to add following code in any of the initialization script of your shell/terminal.
cats_dont_meaow() { 
  if [ $1 = "meaow"]; then
    echo "Cats don\'t meaow in parallel universe."
  else
    cat $*
  fi
}
alias cat=cats_dont_meaow
Thanks to https://cdn.meme.am/
Consider the application of the script in case you have cached your git credentials and you accidentally hit enter after randomly typing some keys that may become git push origin master. This function will save your gits (pun intended).
block_git_push() {
  if [ $1 = "push" ]; then
    echo "\"push\" is blocked temporarily to prevent volcano eruption."
  else
    git $*
  fi
}
alias git=block_git_push
Gist: https://gist.github.com/fahadsiddiqui/ecb81755ae19eb5add1fce17bf7c730a

No comments :

Post a Comment