You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bashrc 15 KiB

13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. #!/bin/bash
  2. ##########################
  3. # system type
  4. alias ismsys=false
  5. alias iscygwin=false
  6. alias iswindows=false
  7. alias isdarwin=false
  8. alias islinux=false
  9. case `uname` in
  10. (MINGW*) alias ismsys=true ;;
  11. (CYGWIN*) alias iscygwin=true ;;
  12. (Darwin*) alias isdarwin=true ;;
  13. (Linux*) alias islinux=true ;;
  14. esac
  15. ( ismsys || iscygwin ) && alias iswindows=true
  16. ##########################################
  17. null(){
  18. "$@" >/dev/null 2>&1
  19. }
  20. __try_exec(){
  21. type $1 >/dev/null 2>&1 && "$@"
  22. }
  23. export PS1="\$(__my_prompt_function)\$ "
  24. # PROMPT_COMMAND=prompt_function
  25. if false iswindows
  26. then
  27. export PAGER='tr -d \\r | less'
  28. else
  29. export PAGER="less"
  30. fi
  31. export LESS="-iRMX"
  32. if null type vim
  33. then
  34. export EDITOR=vim
  35. else
  36. export EDITOR=vi
  37. fi
  38. export LC_MESSAGES=C
  39. # export CDPATH=".:~"
  40. export VISUAL="$EDITOR"
  41. export GIT_PAGER="$PAGER"
  42. export GIT_EDITOR="$EDITOR"
  43. ! iswindows && null type stty && {
  44. stty stop undef # unbind C-s to stop displaying output
  45. # stty erase '^h'
  46. }
  47. if iswindows; then
  48. # export TMP=/tmp
  49. # export TEMP=/tmp
  50. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  51. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  52. export USER=$USERNAME
  53. fi
  54. #######################
  55. iswindows && alias tty="echo cmd.exe"
  56. uname -a
  57. echo TERM $TERM connected to $(tty), running $BASH $BASH_VERSION
  58. echo
  59. ###################################
  60. # some aliases and functions
  61. test "$TERM" == dumb || _coloroption=" --color=always"
  62. iswindows || _timeoption=" --time-style=long-iso"
  63. alias ls="ls -hCF${_coloroption}${_timeoption}"
  64. # export GREP_OPTIONS=""
  65. alias grep="grep -n${_coloroption}"
  66. iswindows && alias grep="grep -n"
  67. # alias ll="ls -l"
  68. # alias la="ls -A"
  69. # alias lla="ls -Al"
  70. # alias less=""
  71. # alias vl=/usr/share/vim/vimcurrent/macros/less.sh
  72. alias em="emacs -nw"
  73. null type vim && alias vi=vim
  74. alias pstree="LANG=C pstree"
  75. alias cp="cp -v"
  76. alias mv="mv -v"
  77. alias psall="ps auxww"
  78. alias q=exit
  79. alias p="$PAGER"
  80. alias c=cat
  81. alias e3=e3em
  82. alias dirs="dirs -v -l | \grep -v \$(printf '%s$' \$PWD)"
  83. alias po=popd
  84. alias pu=pushd
  85. alias sudo="sudo " # use aliases through sudo
  86. alias halt="sudo halt"
  87. alias reboot="sudo reboot"
  88. alias suspend="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  89. /org/freedesktop/UPower org.freedesktop.UPower.Suspend"
  90. alias hibernate="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  91. /org/freedesktop/UPower org.freedesktop.UPower.Hibernate"
  92. alias rand="echo \$RANDOM"
  93. alias ut="ssh 6365454829@un001.ecc.u-tokyo.ac.jp"
  94. alias xunp="file-roller -h"
  95. alias pc="sudo \paco -D"
  96. alias pcalc="python -i -c 'from math import *' "
  97. alias py3=python3
  98. alias py2=python2
  99. alias _reloadrc="test -f ~/.bashrc && source ~/.bashrc"
  100. # alias mytime="date +%Y%m%d-%H%M%S"
  101. alias sh="ENV=$HOME/.shrc PS1=\$\ sh"
  102. # type trash >/dev/null 2>&1 && alias rm=trash
  103. alias wic=wicd-curses
  104. alias wil="wicd-cli -y -l | head"
  105. alias wicn="wicd-cli -y -c -n"
  106. alias aptin="apt-get install"
  107. alias aptsearch="apt-cache search"
  108. alias aptshow="apt-cache show"
  109. alias yt=yaourt
  110. null type pacman-color && {
  111. alias pacman=pacman-color
  112. export pacman_program=pacman-color # used by pacmatic
  113. export PACMAN=pacman-color # used by yaourt
  114. }
  115. null type pacmatic && {
  116. alias pacman="pacmatic"
  117. export PACMAN="pacmatic"
  118. }
  119. alias ubuntu-upgrade="sudo apt-get autoremove --yes && sudo apt-get update --yes && sudo apt-get upgrade --yes"
  120. alias arch-upgrade="sudo pacman -Syu"
  121. alias port-upgrade="port selfupdate && port sync && port upgrade installed"
  122. if iscygwin; then
  123. null type windate || alias windate="/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%'"
  124. alias cygsu="cygstart /cygwinsetup.exe"
  125. alias emacs="CYGWIN=tty emacs -nw"
  126. alias ls="ls -CFG $(iswindows || test "$TERM" == dumb || echo --color=auto)"
  127. fi
  128. alias g=git
  129. if null type _git # enable programmable completion for g
  130. then
  131. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  132. || complete -o default -o nospace -F _git g
  133. fi
  134. mcrypt-stream(){
  135. test $# -eq 2 || return 1
  136. case $1 in
  137. en)
  138. mcrypt --key $2 | base64 ;;
  139. de)
  140. base64 -d | mcrypt -d --key $2 ;;
  141. esac
  142. }
  143. gpg-stream(){
  144. test $# -eq 2 || return 1
  145. case $1 in
  146. en)
  147. gpg --passphrase $2 -c --batch |base64 ;;
  148. de)
  149. base64 -d|gpg --passphrase $2 -d --batch ;;
  150. esac
  151. }
  152. alias enst="gpg-stream en"
  153. alias dest="gpg-stream de"
  154. showinfo(){
  155. echo "Japanese letters are 表示可能"
  156. __try_exec diskinfo
  157. ! isdarwin && test -n "${DISPLAY}" && {
  158. __try_exec xrandr | \grep --color=never ^Screen
  159. }
  160. iswindows || __try_exec finger $USER
  161. LANG=C __try_exec id
  162. __try_exec xset q
  163. }
  164. x(){
  165. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  166. #mkdir -p ~/.my/log
  167. # nohup startx >~/.my/log/xorg.log 2>&1 &
  168. # exit
  169. exec startx
  170. else
  171. echo "X cant be started! Maybe another X is already running or something." 1>&2
  172. fi
  173. }
  174. bak(){
  175. for file in "$@"
  176. do
  177. cp -v ${file} ${file}.bak
  178. done
  179. }
  180. di(){
  181. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  182. then
  183. local diffcmd=colordiff
  184. else
  185. local diffcmd=diff
  186. fi
  187. ${diffcmd} -u "$@" | ${PAGER}
  188. }
  189. throw-away(){
  190. mkdir -p ~/.my/tb
  191. for file in "$@"
  192. do
  193. mv $file ~/.my/tb
  194. done
  195. }
  196. mkcd(){
  197. mkdir -p $1
  198. cd $1
  199. }
  200. catclip(){
  201. if iswindows
  202. then
  203. cat /dev/clipboard | tr -d \\r
  204. else
  205. xclip -o -selection "clipboard"
  206. fi
  207. }
  208. setclip(){
  209. if iswindows
  210. then
  211. if test $# -eq 0
  212. then
  213. sed -e 's/$/\r/' | tee /dev/clipboard
  214. else
  215. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  216. fi
  217. else
  218. if test $# -eq 0
  219. then
  220. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  221. else
  222. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  223. fi
  224. fi
  225. }
  226. if iswindows; then
  227. alias _open_file='cmd.exe //c start ""'
  228. elif isdarwin; then
  229. alias _open_file=open
  230. elif islinux; then
  231. if null type pcmanfm; then
  232. alias _open_file="LC_MESSAGES= pcmanfm"
  233. else
  234. alias _open_file="LC_MESSAGES= xdg-open"
  235. fi
  236. else
  237. alias _open_file=cat
  238. fi
  239. o(){
  240. if test $# -eq 0
  241. then
  242. _open_file . >/dev/null 2>&1 &
  243. else
  244. for f in "$@"
  245. do
  246. if test -d $f
  247. then
  248. _open_file $f >/dev/null 2>&1 &
  249. else
  250. _open_file $f >/dev/null 2>&1 &
  251. fi
  252. done
  253. fi
  254. }
  255. convmv-sjis2utf8-test(){
  256. convmv -r -f sjis -t utf8 *
  257. }
  258. convmv-sjis2utf8-notest(){
  259. convmv -r -f sjis -t utf8 * --notest
  260. }
  261. _my_git_config(){
  262. git config --global user.name '10sr'
  263. git config --global user.email '8slashes+git@gmail.com'
  264. git config --global core.autocrlf false
  265. git config --global core.excludesfile '~/.gitignore'
  266. git config --global color.ui auto
  267. git config --global status.relativePaths false
  268. git config --global status.showUntrackedFiles normal
  269. git config --global log.date iso
  270. git config --global alias.graph "log --graph --date-order -C -M --pretty=tformat:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=iso"
  271. git config --global alias.st "status -s -b"
  272. git config --global alias.b "branch"
  273. git config --global alias.ci "commit --verbose"
  274. git config --global alias.co "checkout"
  275. git config --global alias.cim "commit --verbose -m"
  276. git config --global alias.di "diff --color"
  277. git config --global alias.me "merge --no-ff --stat -v"
  278. git config --global alias.ls "ls-files -v --full-name"
  279. git config --global alias.sl "!sl"
  280. # git config --global alias.my-ls "ls-files | xargs ls"
  281. # git config --global alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  282. git config --global alias.addi "add -i"
  283. if iswindows; then
  284. git config --global core.fileMode false
  285. fi
  286. }
  287. __my_parse_svn_branch() {
  288. local LANG=C
  289. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  290. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  291. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  292. }
  293. __my_svn_ps1(){
  294. if svn status >/dev/null 2>&1
  295. then
  296. local svn_branch=$(__my_parse_svn_branch)
  297. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  298. fi
  299. }
  300. #Change ANSI Colors
  301. _chengecolors(){
  302. echo -e \
  303. "\e]P0000000" \
  304. "\e]P1cd0000" \
  305. "\e]P200cd00" \
  306. "\e]P3cdcd00" \
  307. "\e]P41e90ff" \
  308. "\e]P5cd00cd" \
  309. "\e]P600cdcd" \
  310. "\e]P7353535" \
  311. "\e]P8666666" \
  312. "\e]P9ff9999" \
  313. "\e]Pa99ff99" \
  314. "\e]Pbffff99" \
  315. "\e]Pc9999ff" \
  316. "\e]Pdff99ff" \
  317. "\e]Pe99ffff" \
  318. "\e]Pfffffff"
  319. }
  320. # printf "\e]P7353535" \
  321. _colors(){
  322. echo -e \
  323. "\e[30mBlack" \
  324. "\e[31mRed" \
  325. "\e[32mGreen" \
  326. "\e[33mYellow" \
  327. "\e[34mBlue" \
  328. "\e[35mMagenta" \
  329. "\e[36mCyan" \
  330. "\e[37mWhite"
  331. echo -e \
  332. "\e[30;1mBright Black" \
  333. "\e[31;1mBright Red" \
  334. "\e[32;1mBright Green" \
  335. "\e[33;1mBright Yellow" \
  336. "\e[34;1mBright Blue" \
  337. "\e[35;1mBright Magenta" \
  338. "\e[36;1mBright Cyan" \
  339. "\e[37;1mBright White\n" \
  340. "\e[0m"
  341. }
  342. _my_install_script(){
  343. mkdir -p "$HOME/bin/"
  344. for f in "$@"
  345. do
  346. bn=$(basename "$f")
  347. type $bn >/dev/null 2>&1 || {
  348. if type wget >/dev/null 2>&1
  349. then
  350. wget "$f" -P "$HOME/bin/" &&
  351. chmod u+x "$HOME/bin/${bn}"
  352. elif type curl >/dev/null 2>&1
  353. then
  354. curl --url "$f" --output "$HOME/bin/${bn}" &&
  355. chmod u+x "$HOME/bin/${bn}"
  356. fi
  357. }
  358. done
  359. }
  360. _my_install_script http://www.frexx.de/xterm-256-notes/data/colortable16.sh http://www.frexx.de/xterm-256-notes/data/256colors2.pl
  361. _my_install_symlink_script(){
  362. mkdir -p "$HOME/bin/"
  363. for f in "$@"
  364. do
  365. ln -s "$PWD/$f" "$HOME/bin/"
  366. done
  367. }
  368. winln(){
  369. # for windose make link (actually junction)
  370. if test $# -eq 0
  371. then
  372. {
  373. echo "usage: winln TARGET LINK_NAME"
  374. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  375. echo "About other features run 'junction'."
  376. } 1>&2
  377. return 1
  378. else
  379. junction "$2" "$1"
  380. fi
  381. }
  382. __my_battery_status(){
  383. local dir=/sys/class/power_supply/BAT0
  384. if test -d $dir
  385. then
  386. local st=$(cat $dir/status)
  387. local full=$(cat $dir/charge_full)
  388. local now=$(cat $dir/charge_now)
  389. local rate=$(expr $now \* 100 / $full)
  390. printf "$1" "${st}:${rate}%"
  391. fi
  392. }
  393. alias bat='__my_battery_status %s\\n'
  394. ip-address(){
  395. local ip=$(LANG=C ifconfig | \grep --color=never "inet " | \grep --color=never -v "127.0.0.1" | awk '{print $2}')
  396. test -n "$ip" && printf $1 $ip
  397. }
  398. __my_prompt_function(){ # used by PS1
  399. # remove __try_exec from function
  400. local lastreturn=$
  401. if test "${TERM}" == dumb
  402. then
  403. local c1=
  404. local c2=
  405. local c3=
  406. local cdef=
  407. else
  408. local c1="\e[1;31m" # color for PWD
  409. local c2="\e[36m" # color for user
  410. local c3="\e[1;30m" # color for OLDPWD
  411. local c4="\e[1;32m" # color for ::
  412. local cdef="\e[0m"
  413. fi
  414. if iswindows
  415. then
  416. local pwd=$PWD
  417. local oldpwd=$OLDPWD
  418. local date=$(/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%')
  419. else
  420. local pwd=$(echo "${PWD}/" | sed -e "s#${HOME}#~#")
  421. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s#${HOME}#~#")
  422. local jobnum=$(jobs | wc -l) # a strange job exists...
  423. local git=$(__try_exec __git_ps1 [GIT:%s])
  424. local date=$(LANG=C __try_exec date +"%a, %d %b %Y %T %z")
  425. local dirs=$(dirs | wc -l)
  426. fi
  427. # local svn=$(type svn >/dev/null 2>&1 && __try_exec __my_svn_ps1 [SVN:%s])
  428. if test -z "$DISPLAY" && ! iswindows
  429. then
  430. local ip=$(ip-address [Addr:%s])
  431. local bst="/tmp/${USER}-tmp/batterystatus"
  432. test -f $bst && local battery="[Battery:$(sed -e 's`%`%%`g' $bst)]"
  433. __my_battery_status %s >$bst &
  434. fi
  435. # local battery=$(battery-state [%s] | sed -e 's`%`%%`g') # very slow
  436. printf "${c4}::${cdef} [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}${battery}${ip}\n"
  437. printf "${c4}::${cdef} ${c2}${USER}@${HOSTNAME}${cdef} ${date}\n"
  438. printf "${c4}::${cdef} shlv:${SHLVL} dirs:${dirs} last:${lastreturn} "
  439. }
  440. _PS1="\e[32m:: \e[0m[\e[31m\w/\e[0m]\n\
  441. \e[32m:: \e[36m\u@\H \e[0m\d \t bash \v\n\
  442. \e[32m:: \e[0mshlv:${SHLVL} hist:\! last:\$? \$ "
  443. iswindows && PS1=$_PS1
  444. __my_set_title(){
  445. title="$(echo $@)"
  446. case $TERM in
  447. (rxvt*|xterm*|aterm|screen*)
  448. test -t 1 &&
  449. test -n "$DISPLAY" &&
  450. test -z "$EMACS" &&
  451. echo -n -e "\033]0;${title}\007"
  452. ;;
  453. esac
  454. }
  455. export PROMPT_COMMAND="__my_set_title \${USER}@\${HOSTNAME}\ \${PWD};"
  456. # copied from https://wiki.archlinux.org/index.php/X_resources
  457. invader(){
  458. # ANSI color scheme script featuring Space Invaders
  459. #
  460. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  461. # Modified by lolilolicon
  462. #
  463. f=3 b=4
  464. for j in f b; do
  465. for i in {0..7}; do
  466. printf -v $j$i %b "\e[${!j}${i}m"
  467. done
  468. done
  469. bld=$'\e[1m'
  470. rst=$'\e[0m'
  471. cat << EOF
  472. $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  473. $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  474. $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
  475. $f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst
  476. $bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  477. $bld$f1█▄█▀███▀█▄█ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4█▄█▀███▀█▄█ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  478. $bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst
  479. $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
  480. $f7▌$rst
  481. $f7▌$rst
  482. $f7 ▄█▄ $rst
  483. $f7▄█████████▄$rst
  484. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  485. EOF
  486. }
  487. #/etc/lsb-release