Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

599 Zeilen
15 KiB

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