Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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