Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

558 рядки
15 KiB

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