Skip to content

Instantly share code, notes, and snippets.

@ArnonEilat
Last active March 8, 2020 14:27
Show Gist options
  • Save ArnonEilat/d3d75cfcb3a4b181fcbf to your computer and use it in GitHub Desktop.
Save ArnonEilat/d3d75cfcb3a4b181fcbf to your computer and use it in GitHub Desktop.
Nice to have bashrc shortcuts to copy and paste
Black="$(tput setaf 0)"
BlackBG="$(tput setab 0)"
DarkGrey="$(tput setaf 0)"
LightGrey="$(tput setaf 7)"
LightGreyBG="$(tput setab 7)"
White="$(tput setaf 7)"
Red="$(tput setaf 1)"
RedBG="$(tput setab 1)"
LightRed="$(tput setaf 1)"
Green="$(tput setaf 2)"
GreenBG="$(tput setab 2)"
LightGreen="$(tput setaf 2)"
Brown="$(tput setaf 3)"
BrownBG="$(tput setab 3)"
Yellow="$(tput setaf 3)"
Blue="$(tput setaf 4)"
BlueBG="$(tput setab 4)"
LightBlue="$(tput bold ; tput setaf 4)"
Purple="$(tput setaf 5)"
PurpleBG="$(tput setab 5)"
Pink="$(tput bold ; tput setaf 5)"
Cyan="$(tput setaf 6)"
CyanBG="$(tput setab 6)"
LightCyan="$(tput setaf 6)"
NC="$(tput sgr0)" # No Color
PS1='\[$LightGreen\]\t \[$Blue\]\u \[$LightCyan\]\w \[$Yellow\]\$\[$White\]'
export PAGER="most"
alias psinf="xprop _NET_WM_PID | sed 's/_NET_WM_PID(CARDINAL) = //' | ps \`cat\`"
alias min='wmctrl -r :SELECT: -b remove,maximized_vert,maximized_horz'
alias weather='curl wttr.in/tel-aviv'
alias ccat='pygmentize -g'
alias p='ps -aux'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../../'
alias ~='cd ~'
alias cd-='cd -'
alias t='tree -ph'
alias t='exa --long --tree -I node_modules'
alias h="history | cut -c 8- | sort -u | percol --match-method regex | xclip -sel clip"
# alias h='history | cut -c 8- | sort | uniq | percol'
alias n='npm run start'
alias ntl='ntl -A'
alias y='yarn run start'
alias ntl='ntl -A'
alias l='exa --long --header --git -F -g -U -a -H --group-directories-first --ignore-glob ".*DS_Store|.*localized"'
alias l='ls -lhAiB --color=auto'
alias l-size="du -h --max-depth=1 | sort -rh" # list folders by size in current directory
alias g='goto $(goto -l | percol)'
alias git-checkout='git checkout $(git branch | percol)'
alias git-grep-all="git branch -a | tr -d \* | sed '/->/d' | xargs git grep" # git grep across all branches
alias du-dir='du -h --max-depth=1'
alias pcd='cd "$(find . -maxdepth 1 -type d |percol)"'
alias cdp='cd "$(find . -maxdepth 1 -type d |percol)"'
alias c='clear'
alias j='jobs -l'
alias path='echo -e ${PATH//:/\\n}'
alias myip="curl http://ipecho.net/plain; echo"
alias ipInfo.io="curl ipinfo.io"
alias calculator='bc -l'
alias header='curl -I'
## get top process eating memory
alias ps-mem='ps auxf | sort -nr -k 4 |cut -c 1-120| head -10'
alias serve-php='php -S 127.0.0.1:8080'
## get top process eating cpu ##
alias ps-cpu10='ps auxf | sort -nr -k 3 | cut -c 1-120|head -10'
function screen-shot(){
secs=3
while [ $secs -gt 0 ]; do
echo -ne "$secs\033[0K\r"
sleep 1
: $((secs--))
done
scrot /home/arnon/Downloads/screen.png
echo "The screen shot is on /home/arnon/Downloads/screen.png"
echo "and the path on the clip board."
echo "/home/arnon/Downloads/screen.png"|xclip -sel clip
read -p "Open with gimp (y/n)?" CONT
if [ "$CONT" = "y" ]; then
gimp "/home/arnon/Downloads/screen.png" > /dev/null 2>&1 &
fi
}
# alias rename='vidir'
alias random-words="shuf -n4 /usr/share/dict/words | tr '\n' ' ' | xclip -sel clip"
function rename-to-lowercase(){
echo "Translating all uppercase names to lower"
rename 'y/A-Z/a-z/' *
}
function f(){
# s=$(zenity --entry --text="String to find" 2> /dev/null)
read -p "String to find: " s
s=$(locate $s | percol --match-method regex)
echo $s
echo $s | tr -d '\n' |xclip -sel clip
}
up () {
COUNTER=$1
while [[ $COUNTER -gt 0 ]]
do
UP="${UP}../"
COUNTER=$(( $COUNTER -1 ))
done
echo "cd $UP"
cd $UP
UP=''
}
cdl(){ # cd & ls
cd"$@";
ls -al;
}
oldify(){
branchName=$(git branch | grep -v 'old/' | percol | sed 's/ *//g')
git branch -m $branchName "old/$branchName"
}
killByPort() {
if [[ $# -eq 0 ]] ; then
printf 'Missing port argument.\nUsage:\n\tkillByPort 8080\n'
return
fi
port=$(lsof -n -i4TCP:$1 | grep LISTEN | awk '{ print $2 }')
kill -9 $port
}
function cdr { # cd ranger
tempfile='/tmp/chosendir'
/usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}"
test -f "$tempfile" &&
if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
cd -- "$(cat "$tempfile")"
fi
rm -f -- "$tempfile"
}
alias serve='python -m SimpleHTTPServer'
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
password-generator-to-clipboard() {
local l=$1
[ "$l" == "" ] && l=16
p=`tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs`
echo ${p}|xclip -sel clip
echo "The password is on the clipboard"
}
explain () {
if [ "$#" -eq 0 ]; then
while read -p "Command: " cmd; do
curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$cmd"
done
echo "Bye!"
elif [ "$#" -eq 1 ]; then
curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$1"
else
echo "Usage"
echo "explain interactive mode."
echo "explain 'cmd -o | ...' one quoted command to explain it."
fi
}
oldify(){
branchName=$(git branch | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
git checkout -b old/${branchName}
}
setTitle() {
if [ -z "$1" ] # Is parameter #1 zero length?
then
echo "No parameter passed" # Or no parameter passed.
else
echo -en "\033]0;$1\a"
fi
}
function day() {
d=`date +%u`
case $d in
7 )
echo "ראשון" |rev;;
1 )
echo "שני" |rev;;
2 )
echo "שלישי" |rev;;
3 )
echo "רביעי" |rev;;
4)
echo "חמישי" |rev;;
5)
echo "שישי" |rev;;
6)
echo "שבת" |rev;;
esac
}
echo "NODE_ENV: "$NODE_ENV
echo "Node Version:" $(nvm current)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment