Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

bashrc 11 KiB

13 år sedan
13 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
12 år sedan
12 år sedan
13 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
13 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
13 år sedan
12 år sedan
13 år sedan
13 år sedan
12 år sedan
12 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
13 år sedan
13 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. #!/bin/bash
  2. ##########################
  3. # system type
  4. alias ismsys=false
  5. alias iscygwin=false
  6. alias iswindows="iscygwin || ismsys"
  7. alias isdarwin=false
  8. alias islinux=false
  9. case `uname` in
  10. (MINGW32*) alias ismsys=true ;;
  11. (CYGWIN*) alias iscygwin=true ;;
  12. (Darwin*) alias isdarwin=true ;;
  13. (Linux*) alias islinux=true ;;
  14. esac
  15. ##########################################
  16. null(){
  17. "$@" >/dev/null 2>&1
  18. }
  19. __try_exec(){
  20. type $1 >/dev/null 2>&1 && "$@"
  21. }
  22. export PS1="\$(__my_prompt_function)\$ "
  23. # PROMPT_COMMAND=prompt_function
  24. if false iswindows
  25. then
  26. export PAGER='tr -d \\r | less'
  27. else
  28. export PAGER="less"
  29. fi
  30. if false null type vim
  31. then
  32. export EDITOR=vim
  33. else
  34. export EDITOR=vi
  35. fi
  36. export VISUAL="$EDITOR"
  37. export LESS="-iRMX"
  38. export LC_MESSAGES=C
  39. export CDPATH=".:~"
  40. export GIT_PAGER="$PAGER"
  41. export GIT_EDITOR="$EDITOR"
  42. null type stty && {
  43. stty stop undef # unbind C-s to stop displaying output
  44. stty erase '^h'
  45. }
  46. if iswindows; then
  47. # export TMP=/tmp
  48. # export TEMP=/tmp
  49. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  50. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  51. export USER=$USERNAME
  52. fi
  53. #######################
  54. uname -a
  55. if [ "${EMACS}" = "t" ]; then # for emacs shell
  56. true export PS1="\u@\H \d \t \w\nemacs shell\$ "
  57. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # for emacs term
  58. echo "Emacs Term"
  59. fi
  60. # if test -f /etc/issue
  61. # then
  62. # cat /etc/issue
  63. # fi
  64. ###################################
  65. # some aliases and functions
  66. alias ls="ls -hCF $(test "$TERM" == dumb || echo --color=auto\ )--time-style=long-iso"
  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. alias pstree="LANG=C pstree"
  74. # alias apt-get="sudo apt-get"
  75. alias ut="ssh 6365454829@un001.ecc.u-tokyo.ac.jp"
  76. alias rand="echo \$RANDOM"
  77. alias xunp="file-roller -h"
  78. alias pacome="sudo \paco -D"
  79. alias psall="ps auxww"
  80. alias q=exit
  81. alias p="$PAGER"
  82. alias c=cat
  83. alias pcalc="python -i -c 'from math import *' "
  84. alias py3=python3
  85. alias _reloadrc="test -f ~/.bashrc && source ~/.bashrc"
  86. alias sudo="sudo " # use aliases through sudo
  87. alias e3=e3em
  88. alias mytime="date +%Y%m%d-%H%M%S"
  89. alias sh="ENV=$HOME/.shrc PS1=\$\ sh"
  90. alias halt="sudo halt"
  91. alias reboot="sudo reboot"
  92. # type trash >/dev/null 2>&1 && alias rm=trash
  93. alias aptin="apt-get install"
  94. alias aptsearch="apt-cache search"
  95. alias aptshow="apt-cache show"
  96. alias yt=yaourt
  97. null type pacman-color && {
  98. alias pacman=pacman-color
  99. export pacman_program=pacman-color # used by pacmatic
  100. export PACMAN=pacman-color # used by yaourt
  101. }
  102. null type pacmatic && {
  103. alias pacman=pacmatic
  104. export PACMAN=pacmatic
  105. }
  106. alias ubuntu-upgrade="sudo apt-get autoremove --yes && sudo apt-get update --yes && sudo apt-get upgrade --yes"
  107. alias arch-upgrade="yaourt -Syu"
  108. alias port-upgrade="port selfupdate && port sync && port upgrade installed"
  109. if iscygwin; then
  110. null type windate || alias windate="/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%'"
  111. alias cygsu="cygstart /cygwinsetup.exe"
  112. alias emacs="CYGWIN=tty emacs -nw"
  113. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto)"
  114. fi
  115. alias g=git
  116. if null type _git # enable programmable completion for g
  117. then
  118. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  119. || complete -o default -o nospace -F _git g
  120. fi
  121. showinfo(){
  122. echo "Japanese letters are 表示可能"
  123. __try_exec diskinfo
  124. ! isdarwin && test -n "${DISPLAY}" && {
  125. __try_exec xrandr | grep --color=never ^Screen
  126. }
  127. iswindows || __try_exec finger $USER
  128. LANG=C __try_exec id
  129. __try_exec xset q
  130. }
  131. x(){
  132. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  133. nohup startx >~/.backup/log/xorg.log 2>&1 &
  134. else
  135. echo "X cant be started! Maybe another X is already running!" 1>&2
  136. fi
  137. }
  138. export __MYGITBAREREP="${HOME}/dbx/.git-bare"
  139. git-make-local-rep(){
  140. test $# -eq 0 && {
  141. echo "specify repository name." 1>&2
  142. return 1
  143. }
  144. dir="${__MYGITBAREREP}/$1.git"
  145. cdir=$PWD
  146. if test -d "$dir"
  147. then
  148. echo "dir $dir already exist!" 1>&2
  149. else
  150. mkdir -p "$dir" && {
  151. cd "$dir" &&
  152. git init --bare --shared=all
  153. }
  154. fi
  155. cd ${cdir}
  156. }
  157. bak(){
  158. for file in "$@"
  159. do
  160. mv -v ${file} ${file}.bak
  161. done
  162. }
  163. di(){
  164. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  165. then
  166. local diffcmd=colordiff
  167. else
  168. local diffcmd=diff
  169. fi
  170. ${diffcmd} -u "$@" | ${PAGER}
  171. }
  172. throw-away(){
  173. mkdir -p ~/.backup/tb
  174. for file in "$@"
  175. do
  176. mv $file ~/.backup/tb
  177. done
  178. }
  179. mkcd(){
  180. mkdir -p $1
  181. cd $1
  182. }
  183. catclip(){
  184. if iswindows
  185. then
  186. cat /dev/clipboard | tr -d \\r
  187. else
  188. xclip -o -selection "clipboard"
  189. fi
  190. }
  191. setclip(){
  192. if iswindows
  193. then
  194. if test $# -eq 0
  195. then
  196. sed -e 's/$/\r/' | tee /dev/clipboard
  197. else
  198. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  199. fi
  200. else
  201. if test $# -eq 0
  202. then
  203. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  204. else
  205. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  206. fi
  207. fi
  208. }
  209. o(){
  210. if [ $# -eq 0 ]
  211. then
  212. local f=.
  213. else
  214. local f="$1"
  215. fi
  216. if iswindows
  217. then
  218. cmd.exe //c start "" "$f"
  219. elif isdarwin
  220. then
  221. open "$f"
  222. elif type pcmanfm >/dev/null 2>&1
  223. then
  224. pcmanfm "$f"
  225. else
  226. xdg-open "$f"
  227. fi
  228. }
  229. convmv-sjis2utf8-test(){
  230. convmv -r -f sjis -t utf8 *
  231. }
  232. convmv-sjis2utf8-notest(){
  233. convmv -r -f sjis -t utf8 * --notest
  234. }
  235. _mygitconfig(){
  236. git config --global user.name '10sr'
  237. git config --global user.email '8slashes+git@gmail.com'
  238. git config --global core.autocrlf false
  239. git config --global color.ui auto
  240. git config --global status.relativePaths false
  241. git config --global status.showUntrackedFiles normal
  242. git config --global alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  243. git config --global alias.st "status -s"
  244. git config --global alias.b "branch"
  245. git config --global alias.ci "commit --verbose"
  246. git config --global alias.co "checkout"
  247. git config --global alias.cim "commit --verbose -m"
  248. git config --global alias.di "diff --color"
  249. git config --global alias.me "merge --no-ff --stat -v"
  250. git config --global alias.ls "ls-files -v --full-name"
  251. git config --global alias.sl "!sl"
  252. # git config --global alias.my-ls "ls-files | xargs ls"
  253. # git config --global alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  254. git config --global alias.addi "add -i"
  255. if iswindows; then
  256. git config --global core.fileMode false
  257. fi
  258. }
  259. __my_parse_svn_branch() {
  260. local LANG=C
  261. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  262. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  263. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  264. }
  265. __my_svn_ps1(){
  266. if svn status >/dev/null 2>&1
  267. then
  268. local svn_branch=$(__my_parse_svn_branch)
  269. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  270. fi
  271. }
  272. #Change ANSI Colors
  273. _chengecolors(){
  274. echo -e \
  275. "\e]P0000000" \
  276. "\e]P1cd0000" \
  277. "\e]P200cd00" \
  278. "\e]P3cdcd00" \
  279. "\e]P41e90ff" \
  280. "\e]P5cd00cd" \
  281. "\e]P600cdcd" \
  282. "\e]P7353535" \
  283. "\e]P8666666" \
  284. "\e]P9ff9999" \
  285. "\e]Pa99ff99" \
  286. "\e]Pbffff99" \
  287. "\e]Pc9999ff" \
  288. "\e]Pdff99ff" \
  289. "\e]Pe99ffff" \
  290. "\e]Pfffffff"
  291. }
  292. # printf "\e]P7353535" \
  293. _echocolors(){
  294. echo -e \
  295. "\e[30mBlack\n" \
  296. "\e[31mRed\n" \
  297. "\e[32mGreen\n" \
  298. "\e[33mYellow\n" \
  299. "\e[34mBlue\n" \
  300. "\e[35mMagenta\n" \
  301. "\e[36mCyan\n" \
  302. "\e[37mWhite\n" \
  303. "\e[30;1mBright Black\n" \
  304. "\e[31;1mBright Red\n" \
  305. "\e[32;1mBright Green\n" \
  306. "\e[33;1mBright Yellow\n" \
  307. "\e[34;1mBright Blue\n" \
  308. "\e[35;1mBright Magenta\n" \
  309. "\e[36;1mBright Cyan\n" \
  310. "\e[37;1mBright White\n" \
  311. "\e[0m"
  312. }
  313. # http://myminios.googlecode.com/svn-history/r10/trunk/colortable16.sh
  314. winln(){
  315. # for windose make link (actually junction)
  316. if test $# -eq 0
  317. then
  318. {
  319. echo "usage: winln TARGET LINK_NAME"
  320. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  321. echo "About other features run 'junction'."
  322. } 1>&2
  323. return 1
  324. else
  325. junction "$2" "$1"
  326. fi
  327. }
  328. battery-status(){
  329. local dir=/sys/class/power_supply/BAT0
  330. if test -d $dir
  331. then
  332. local st=$(cat $dir/status)
  333. local full=$(cat $dir/charge_full)
  334. local now=$(cat $dir/charge_now)
  335. local rate=$(expr $now \* 100 / $full)
  336. printf $1 "${st}:${rate}%"
  337. fi
  338. }
  339. alias bat='battery-status %s\\n'
  340. battery-status2(){
  341. local dir=/sys/class/power_supply/BAT0
  342. . $dir/uevent
  343. local rate=$(expr $POWER_SUPPLY_CHARGE_NOW \* 100 / $POWER_SUPPLY_CHARGE_FULL)
  344. echo ${POWER_SUPPLY_STATUS}:${rate}%
  345. }
  346. ip-address(){
  347. local ip=$(LANG=C ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}')
  348. test -n "$ip" && printf $1 $ip
  349. }
  350. __my_prompt_function(){ # used by PS1
  351. local lastreturn=$?
  352. if test "${TERM}" == dumb
  353. then
  354. local c1=
  355. local c2=
  356. local c3=
  357. local cdef=
  358. else
  359. local c1="\e[33m"
  360. local c2="\e[36m"
  361. local c3="\e[37m"
  362. local cdef="\e[0m"
  363. fi
  364. if iswindows
  365. then
  366. local pwd=$PWD
  367. local oldpwd=$OLDPWD
  368. local jobnum=
  369. if git branch >/dev/null 2>&1
  370. then
  371. local git="[GIT]"
  372. else
  373. local git=
  374. fi
  375. local date=$(/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%')
  376. else
  377. local pwd=$(echo "${PWD}/" | sed -e "s#${HOME}#~#")
  378. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s#${HOME}#~#")
  379. local jobnum=$(jobs | wc -l)
  380. local git=$(__try_exec __git_ps1 [GIT:%s])
  381. local date=$(LANG=C __try_exec date +"%a, %d %b %Y %T %z")
  382. fi
  383. # local svn=$(type svn >/dev/null 2>&1 && __try_exec __my_svn_ps1 [SVN:%s])
  384. if test -z "$DISPLAY"
  385. then
  386. local ip=$(ip-address [Addr:%s])
  387. test -f ~/.batterystatus && local battery="[Battery:$(cat ~/.batterystatus | sed -e 's`%`%%`g')]"
  388. fi
  389. local tty=$(__try_exec tty | sed -e 's:/dev/::')
  390. # local battery=$(battery-state [%s] | sed -e 's`%`%%`g') # very slow
  391. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}${battery}${ip}\n"
  392. printf "${c2}${USER}@${HOSTNAME}${cdef} ${tty} ${date} ${BASH} ${BASH_VERSION}\n"
  393. printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} "
  394. }