您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

13 年前
13 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
13 年前
13 年前
12 年前
13 年前
12 年前
12 年前
12 年前
13 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
13 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
13 年前
12 年前
13 年前
12 年前
12 年前
12 年前
12 年前
13 年前
12 年前
12 年前
12 年前
13 年前
12 年前
13 年前
12 年前
13 年前
12 年前
13 年前
13 年前
13 年前
13 年前
12 年前
13 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. #!/bin/bash
  2. # If not running interactively, don't do anything
  3. [ -z "$PS1" ] && return
  4. ##########################
  5. # system type
  6. alias ismsys=false
  7. alias iscygwin=false
  8. alias iswindows=false
  9. alias isdarwin=false
  10. alias islinux=false
  11. case `uname` in
  12. (MINGW*) alias ismsys=true ;;
  13. (CYGWIN*) alias iscygwin=true ;;
  14. (Darwin*) alias isdarwin=true ;;
  15. (Linux*) alias islinux=true ;;
  16. esac
  17. ( ismsys || iscygwin ) && alias iswindows=true
  18. ##########################################
  19. null(){
  20. "$@" >/dev/null 2>&1
  21. }
  22. __try_exec(){
  23. type $1 >/dev/null 2>&1 && "$@"
  24. }
  25. export PS1 # PS1 is defined later
  26. # PROMPT_COMMAND=prompt_function
  27. if false iswindows
  28. then
  29. export PAGER='tr -d \\r | less'
  30. else
  31. export PAGER="less"
  32. fi
  33. export LESS="-iRMXF"
  34. if null type vim
  35. then
  36. export EDITOR=vim
  37. else
  38. export EDITOR=vi
  39. fi
  40. export LC_MESSAGES=C
  41. # export CDPATH=".:~"
  42. export VISUAL="$EDITOR"
  43. export GIT_PAGER="$PAGER"
  44. export GIT_EDITOR="$EDITOR"
  45. echo "$TERM" | grep '^screen' >/dev/null 2>&1 || export TERM_ORIG=$TERM
  46. test -z "$TMP" && export TMP=/tmp/${USER}-tmp
  47. mkdir -p "$TMP"
  48. ! iswindows && null type stty && {
  49. stty stop undef # unbind C-s to stop displaying output
  50. # stty erase '^h'
  51. }
  52. if iswindows; then
  53. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  54. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  55. export USER=$USERNAME
  56. fi
  57. #######################
  58. iswindows && alias tty="echo cmd.exe"
  59. type fortune >/dev/null 2>&1 && {
  60. echo
  61. fortune
  62. echo
  63. fortune -o
  64. echo
  65. }
  66. uname -a
  67. echo TERM $TERM $(tput colors) colors connected to $(tty), running $BASH $BASH_VERSION
  68. echo
  69. ###################################
  70. # some aliases and functions
  71. isdarwin || test "$TERM" == dumb || _coloroption=" --color=always"
  72. isdarwin || iswindows || _timeoption=" --time-style=long-iso"
  73. alias ls="ls -hCF${_coloroption}${_timeoption}"
  74. # export GREP_OPTIONS=""
  75. alias grep="grep -n${_coloroption}"
  76. iswindows && alias grep="grep -n"
  77. # alias ll="ls -l"
  78. # alias la="ls -A"
  79. # alias lla="ls -Al"
  80. # alias less=""
  81. alias em="emacs -nw"
  82. null type vim && alias vi=vim
  83. alias pstree="LANG=C pstree"
  84. alias cp="cp -v"
  85. alias mv="mv -v"
  86. alias psaux="ps auxww"
  87. alias q=exit
  88. alias e3=e3em
  89. alias dirs="dirs -v -l | \grep -v \$(printf '%s$' \$PWD)"
  90. alias po=popd
  91. alias pu=pushd
  92. alias sudo="sudo " # use aliases through sudo
  93. alias halt="sudo halt"
  94. alias reboot="sudo reboot"
  95. alias suspend="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  96. /org/freedesktop/UPower org.freedesktop.UPower.Suspend"
  97. alias hibernate="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  98. /org/freedesktop/UPower org.freedesktop.UPower.Hibernate"
  99. alias rand="echo \$RANDOM"
  100. alias xunp="file-roller -h"
  101. alias pc="sudo \paco -D"
  102. alias pycalc="python -i -c 'from math import *' "
  103. alias py3=python3
  104. alias py2=python2
  105. alias _reloadrc="test -f ~/.bashrc && source ~/.bashrc"
  106. # alias mytime="date +%Y%m%d-%H%M%S"
  107. alias sh="ENV=$HOME/.shrc PS1=\$\ PROMPT_COMMAND="" sh"
  108. # type trash >/dev/null 2>&1 && alias rm=trash
  109. alias mpg123="mpg123 -C -v --title"
  110. export PLAYER="mpg123 -C -v --title"
  111. alias screen="screen -e^z^z"
  112. alias zcd="cd \`zenity --file-selection --directory\`"
  113. alias pad=notepad
  114. null type gedit && alias pad=gedit
  115. null type leafpad && alias pad=leafpad
  116. alias wic=wicd-curses
  117. alias wil="wicd-cli -y -l | head"
  118. #alias wicn="wicd-cli -y -c -n"
  119. wicn(){
  120. if test $# -eq 0
  121. then
  122. local num
  123. wicd-cli -y -l | head
  124. echo -n "input num: "
  125. read num
  126. test -n "$num" && wicd-cli -y -c -n $num
  127. else
  128. wicd-cli -y -c -n $1
  129. fi
  130. }
  131. alias aptin="apt-get install"
  132. alias aptsearch="apt-cache search"
  133. alias aptshow="apt-cache show"
  134. for f in /usr/share/vim/vimcurrent/macros/less.sh \
  135. /usr/share/vim/vim73/macros/less.sh
  136. do
  137. test -f $f && alias vl=$f && break
  138. done
  139. alias yt=yaourt
  140. null type pacman-color && {
  141. alias pacman=pacman-color
  142. export pacman_program=pacman-color # used by pacmatic
  143. export PACMAN=pacman-color # used by yaourt
  144. }
  145. null type pacmatic && {
  146. alias pacman="pacmatic"
  147. export PACMAN="pacmatic"
  148. }
  149. alias ubuntu-upgrade="sudo apt-get autoremove --yes && sudo apt-get update --yes && sudo apt-get upgrade --yes"
  150. alias arch-upgrade="sudo pacman -Syu"
  151. alias port-upgrade="port selfupdate && port sync && port upgrade installed"
  152. if iscygwin; then
  153. null type windate || alias windate="/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%'"
  154. alias cygsu="cygstart /cygwinsetup.exe"
  155. alias emacs="CYGWIN=tty emacs -nw"
  156. alias ls="ls -CFG $(iswindows || test "$TERM" == dumb || echo --color=auto)"
  157. fi
  158. alias g=git
  159. if null type _git # enable programmable completion for g
  160. then
  161. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  162. || complete -o default -o nospace -F _git g
  163. fi
  164. input(){
  165. local foo
  166. stty -echo
  167. read foo
  168. stty echo
  169. echo $foo
  170. }
  171. tmux(){
  172. if test $# -eq 0
  173. then
  174. if command tmux has -t main
  175. then
  176. command tmux attach -t main
  177. else
  178. command tmux new -s main
  179. fi
  180. else
  181. command tmux "$@"
  182. fi
  183. }
  184. __my_moc_state(){
  185. type mocp >/dev/null 2>&1 || return
  186. test "`mocp -Q %state 2>/dev/null`" == PLAY || return
  187. printf "$1" "`mocp -Q %title 2>/dev/null`"
  188. }
  189. mcrypt-stream(){
  190. test $# -eq 2 || return 1
  191. case $1 in
  192. en)
  193. mcrypt --key $2 | base64 ;;
  194. de)
  195. base64 -d | mcrypt -d --key $2 ;;
  196. esac
  197. }
  198. gpg-stream(){
  199. test $# -eq 2 || return 1
  200. case $1 in
  201. en)
  202. gpg --passphrase $2 -c --batch |base64 ;;
  203. de)
  204. base64 -d|gpg --passphrase $2 -d --batch ;;
  205. esac
  206. }
  207. alias enst="gpg-stream en"
  208. alias dest="gpg-stream de"
  209. showinfo(){
  210. echo "Japanese letters are 表示可能"
  211. __try_exec diskinfo
  212. ! isdarwin && test -n "${DISPLAY}" && {
  213. __try_exec xrandr | \grep --color=never ^Screen
  214. }
  215. iswindows || __try_exec finger $USER
  216. LANG=C __try_exec id
  217. __try_exec xset q
  218. }
  219. x(){
  220. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  221. #mkdir -p ~/.my/log
  222. # nohup startx >~/.my/log/xorg.log 2>&1 &
  223. # exit
  224. exec startx
  225. else
  226. echo "X cant be started! Maybe another X is already running or something." 1>&2
  227. fi
  228. }
  229. bak(){
  230. for file in "$@"
  231. do
  232. cp -v ${file} ${file}.bak
  233. done
  234. }
  235. di(){
  236. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  237. then
  238. local diffcmd=colordiff
  239. else
  240. local diffcmd=diff
  241. fi
  242. ${diffcmd} -u "$@" | ${PAGER}
  243. }
  244. tb(){
  245. local tb=~/.my/tb
  246. mkdir -p $tb
  247. for file in "$@"
  248. do
  249. mv $file $tb
  250. done
  251. }
  252. mkcd(){
  253. mkdir -p $1
  254. cd $1
  255. }
  256. catclip(){
  257. if iswindows
  258. then
  259. cat /dev/clipboard | tr -d \\r
  260. else
  261. xclip -o -selection "clipboard"
  262. fi
  263. }
  264. setclip(){
  265. if iswindows
  266. then
  267. if test $# -eq 0
  268. then
  269. sed -e 's/$/\r/' | tee /dev/clipboard
  270. else
  271. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  272. fi
  273. else
  274. if test $# -eq 0
  275. then
  276. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  277. else
  278. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  279. fi
  280. fi
  281. }
  282. _open_file(){
  283. if iswindows
  284. then
  285. cmd.exe //c start "" "$@"
  286. elif isdarwin
  287. then
  288. open "$@"
  289. elif islinux
  290. then
  291. if null type pcmanfm; then
  292. LC_MESSAGES= pcmanfm "$@" &
  293. else
  294. LC_MESSAGES= xdg-open "$@"
  295. fi
  296. else
  297. cat "$@"
  298. fi
  299. }
  300. o(){
  301. if test $# -eq 0
  302. then
  303. _open_file .
  304. else
  305. for f in "$@"
  306. do
  307. if test -d "$f"
  308. then
  309. _open_file "$f"
  310. else
  311. _open_file "$f"
  312. fi
  313. done
  314. fi
  315. }
  316. convmv-sjis2utf8-test(){
  317. convmv -r -f sjis -t utf8 *
  318. }
  319. convmv-sjis2utf8-notest(){
  320. convmv -r -f sjis -t utf8 * --notest
  321. }
  322. __my_parse_svn_branch() {
  323. local LANG=C
  324. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  325. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  326. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  327. }
  328. __my_svn_ps1(){
  329. if svn status >/dev/null 2>&1
  330. then
  331. local svn_branch=$(__my_parse_svn_branch)
  332. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  333. fi
  334. }
  335. #Change ANSI Colors
  336. _chengecolors(){
  337. echo -e \
  338. "\e]P0000000" \
  339. "\e]P1cd0000" \
  340. "\e]P200cd00" \
  341. "\e]P3cdcd00" \
  342. "\e]P41e90ff" \
  343. "\e]P5cd00cd" \
  344. "\e]P600cdcd" \
  345. "\e]P7353535" \
  346. "\e]P8666666" \
  347. "\e]P9ff9999" \
  348. "\e]Pa99ff99" \
  349. "\e]Pbffff99" \
  350. "\e]Pc9999ff" \
  351. "\e]Pdff99ff" \
  352. "\e]Pe99ffff" \
  353. "\e]Pfffffff"
  354. }
  355. # printf "\e]P7353535" \
  356. _colors(){
  357. echo -e \
  358. "\e[30mBlack" \
  359. "\e[31mRed" \
  360. "\e[32mGreen" \
  361. "\e[33mYellow" \
  362. "\e[34mBlue" \
  363. "\e[35mMagenta" \
  364. "\e[36mCyan" \
  365. "\e[37mWhite"
  366. echo -e \
  367. "\e[30;1mBright Black" \
  368. "\e[31;1mBright Red" \
  369. "\e[32;1mBright Green" \
  370. "\e[33;1mBright Yellow" \
  371. "\e[34;1mBright Blue" \
  372. "\e[35;1mBright Magenta" \
  373. "\e[36;1mBright Cyan" \
  374. "\e[37;1mBright White\n" \
  375. "\e[0m"
  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. test type ifconfig >/dev/null 2>&1 || return 1
  405. local ip=$(LANG=C ifconfig | \grep --color=never "inet " | \grep --color=never -v "127.0.0.1" | awk '{print $2}')
  406. test -n "$ip" && printf $1 $ip
  407. }
  408. __my_ps1_moc(){
  409. local last=$?
  410. __my_moc_state "[MOC:%s]"
  411. return $last
  412. }
  413. __my_ps1_git(){
  414. local last=$?
  415. __try_exec __git_ps1 "[GIT:$(__try_exec git config --get user.name):%s]"
  416. return $last
  417. }
  418. __my_ps1_ipaddr(){
  419. local last=$?
  420. test -z "$DISPLAY" && ! iswindows && ip-address [Addr:%s]
  421. return $last
  422. }
  423. __my_ps1_bttry(){
  424. local last=$?
  425. local bst="${TMP}/batterystatus"
  426. if test -z "$DISPLAY" && ! iswindows
  427. then
  428. test -f $bst && local bstr="$(cat $bst)"
  429. test -n "$bstr" && echo "[Battery:$bstr]"
  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}\${OLDPWD}${__my_cdef}]\$(__my_ps1_git)\$(__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