Skip to content

Instantly share code, notes, and snippets.

@twtw
Last active August 16, 2020 03:26
Show Gist options
  • Save twtw/9f68cb9b1aa54a6ec432b70a14db956f to your computer and use it in GitHub Desktop.
Save twtw/9f68cb9b1aa54a6ec432b70a14db956f to your computer and use it in GitHub Desktop.
.bashrc useful settings
alias ls='ls --color=auto'
alias v='ls -l'
alias lh='ls -lh'
alias dh='df -h'
alias ll='ls -al'
alias irb='irb --simple-prompt'
alias ltips='less $HOME/tips.txt'
alias path='echo $PATH | sed -e "s/:/\n/g"'
# old linux server
alias oldserver='ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 oldserver'
# List only directories
# https://github.com/lyzadanger/dotfiles/blob/master/home/.aliases
alias lsd="ls -lF ${colorflag} | grep --color=never '^d'"
# Stopwatch
alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date'
alias clock='watch -t -n1 "date +%T|figlet -c -f big -W"'
# https://superuser.com/questions/611538/is-there-a-way-to-display-a-countdown-or-stopwatch-timer-in-a-terminal no figlet:
# while true; do echo -ne "`date +"%Y-%m-%d %H:%M:%S"`\r"; done
# IP addresses
alias myip="dig +short myip.opendns.com @resolver1.opendns.com"
alias lessh='LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s" less -R '
alias chat='hipchat_notify --room "MY ROOM" --token {MY TOKEN}'
# https://developer.mozilla.org/en-US/Add-ons/SDK
alias addon-sdk="cd /opt/addon-sdk && source bin/activate; cd -"
# link to old ssh server by alias
# https://unix.stackexchange.com/questions/340844/how-to-enable-diffie-hellman-group1-sha1-key-exchange-on-debian-8-0[ssh - How to enable diffie-hellman-group1-sha1 key exchange on Debian 8.0? - Unix & Linux Stack Exchange]
alias old1='ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 old1'
alias old2='ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 old2'
#
# ~/.bash_profile
#
[[ -f ~/.bashrc ]] && . ~/.bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
if [ -f $HOME/.dot.aliases.sh ]; then
. $HOME/.dot.aliases.sh
fi
if [ -f $HOME/.dot.functions.sh ]; then
. $HOME/.dot.functions.sh
fi
PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
# for journalctl less https://wiki.archlinux.org/index.php?title=Systemd&redirect=no#Journal
export SYSTEMD_LESS=FRXMK
export EDITOR=vim
export LESS=-MM
export NVM_DIR="/home/www/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
if ! echo ${PATH} | /bin/grep -q ${HOME}/.yarn/bin ; then
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
fi
if ! echo ${PATH} | /bin/grep -q ${HOME}/.deno/bin ; then
export DENO_INSTALL="/home/www/.deno"
export PATH="$PATH:$DENO_INSTALL/bin"
fi
# pyenv python
if ! echo ${PATH} | /bin/grep -q ${HOME}/.pyenv/bin ; then
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# pyenv-virtualenv
eval "$(pyenv virtualenv-init -)"
fi
if ! echo ${PATH} | /bin/grep -q ${HOME}/.anyenv/bin ; then
export PATH="$HOME/.anyenv/bin:$PATH"
eval "$(anyenv init -)"
fi
# https://wiki.archlinux.org/index.php/PHP#Commandline_tools
if ! echo ${PATH} | /bin/grep -q ${HOME}/.config/composer/vendor/bin ; then
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
fi
# rvm put at bottom
if ! echo ${PATH} | /bin/grep -q ${HOME}/.rvm/bin ; then
export PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
fi
# function
# list direcory and files sorted by created datetime and less
# https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash[shell - How to check if a variable is set in Bash? - Stack Overflow]
lct(){
ls -lct ${1:-.} | less
}
vl(){
ls -al ${1:-.} | less
}
# http proxy environment variables
hp(){
export http_proxy=http://$1:3128/
}
# ssh tunnel for localhost vnc
sv(){
ssh -L 5901:localhost:5901 $1
}
sv2(){
ssh -L 5902:localhost:5901 $1
}
# ssh tunnel for remote windows vnc example: winxp, vigorlog
svwin(){
ssh -L 5901:$1:5900 $2
}
# vnc viewer by local ssh tunnel
vnc(){
gvncviewer localhost:$1
}
# start vnc server
vs(){
vncserver -geometry 1280x720 :1
}
# tips
tips(){
#now=`date "+%Y-%m-%d %H:%M:%S"`
now=`date "+%F %T"`
echo "($now) write tips:"
tmp=$(</dev/stdin)
#tmp=`echo "$tmp" | sed 's/ /\\\\n/g'`
tmp=`echo "$tmp" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\\\n/g'`
#filename=${1:-/home/user/tips.txt}
filename=${1:-/home/user/tips.txt}
if [ ! -f $filename ]
then
echo '' >> $filename
fi
#sed -i "1s/^/\n$tmp\n===\n/" $filename
#sed -i "1s/^/\n$now\n$tmp\n===\n/" $filename
#sed -i "1s/^/\n$now\n$tmp\n'''\n/" $filename
# with asciidoctor title
sed -i "1s/^/\n=== $now\n$tmp\n\n'''\n/" $filename
less $filename
}
# dbus launch
dl(){
dbus-launch $1
}
# https://github.com/gfredericks/quinedb
qdb () {
./quinedb "$@" > qdb.out 2> qdb.err
mv qdb.out quinedb
chmod +x quinedb
cat qdb.err
rm qdb.err
}
# https://www.maketecheasier.com/rename-files-in-linux/
todot () {
# in lubuntu
rename 's/ /\./g' $1
rename 's/_/\./g' $1
#in arch linux
echo $1
perl-rename 's/ /\./g' "$1"
perl-rename 's/_/\./g' $1
}
# conver asciidoc links to markdown links for github issues
adoc2md () {
sed -e "s/\(.*\)\[\(.*\)\]/- [\2](\1)/g" $1
}
# patronAPI dump
dump () {
curl http://SIERRA-SERVER:4500/PATRONAPI/$1/dump | less
}
# https://code.tutsplus.com/articles/why-you-should-use-rvm--net-19529
myruby () {
PS1="\$(~/.rvm/bin/rvm-prompt) $PS1"
}
# https://github.com/npm/npm/issues/957
nodepath () {
export PATH="$PATH:./node_modules/.bin"
}
# link to old ssh server by function
oldssh() {
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 $1
}
# chinese random names
# https://gist.github.com/twtw/401944[Random Chinese names and Lorem ipsum.]
# usage: cnames or cnames 10
cnames(){
curl -s -d name_count=${1:-5}\&break=2 http://www.richyli.com/name/index.asp | piconv -f big5 -t utf8 | sed -n 88p | awk -F', #' '{print $1}' | sed -e 's/ //g'
}
# chinese random sentences
csentence(){
curl -s -d words=${1:-100} http://www.richyli.com/tool/loremipsum/ | piconv -f big5 -t utf8 | sed -n 36p
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment