Skip to content

Instantly share code, notes, and snippets.

@linwiz
Created November 27, 2014 02:55
Show Gist options
  • Save linwiz/c6aa07b648c0d861bf12 to your computer and use it in GitHub Desktop.
Save linwiz/c6aa07b648c0d861bf12 to your computer and use it in GitHub Desktop.
CLR
#!/bin/bash
# Clear screen, history and trunicate files
_clrTabComplete() {
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $( compgen -W 'normal full log sulog help' -- $cur ) )
return 0
}
complete -F _clrTabComplete clr
_clr_help() {
echo "Usage: clr [option]"
echo "help - This file"
echo "normal - Clear screen and tmux history"
echo "full - Clear screen, tmux history and bash history"
echo "log - Trunicate a file/log"
echo "sulog - Trunicate a file/log with sudo"
}
clr() {
if [[ "$1" == "help" ]]
then
_clr_help
elif [[ "$1" == "normal" ]]
then
clear && tmux clear-history
elif [[ "$1" == "full" ]]
then
clear && tmux clear-history && history -c
elif [[ "$1" == "log" ]]
then
if [[ -z "$2" ]]
then
echo "Please include a file."
_clr_help
elif [[ ! -f "$2" ]]
then
echo "File Does not exist: $2"
_clr_help
else
dd if=/dev/null of="$2"
fi
elif [[ "$1" == "sulog" ]]
then
if [[ -z "$2" ]]
then
echo "Please include a file."
_clr_help
elif [[ ! -f "$2" ]]
then
echo "File Does not exist: $2"
_clr_help
else
sudo dd if=/dev/null of="$2"
fi
elif [[ -z "$1" ]]
then
clear && tmux clear-history
else
echo "Unknown command: $1"
_clr_help
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment