選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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