Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

574 řádky
14 KiB

  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. elif isdarwin
  261. then
  262. pbpaste
  263. else
  264. xclip -o -selection "clipboard"
  265. fi
  266. }
  267. setclip(){
  268. if iswindows
  269. then
  270. if test $# -eq 0
  271. then
  272. sed -e 's/$/\r/' | tee /dev/clipboard
  273. else
  274. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  275. fi
  276. elif isdarwin
  277. then
  278. if test $# -eq 0
  279. then
  280. pbcopy
  281. else
  282. cat "$@" | pbcopy
  283. fi
  284. else
  285. if test $# -eq 0
  286. then
  287. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  288. else
  289. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  290. fi
  291. fi
  292. }
  293. _open_file(){
  294. if iswindows
  295. then
  296. cmd.exe //c start "" "$@"
  297. elif isdarwin
  298. then
  299. open "$@"
  300. elif islinux
  301. then
  302. if null type pcmanfm; then
  303. LC_MESSAGES= pcmanfm "$@" &
  304. else
  305. LC_MESSAGES= xdg-open "$@"
  306. fi
  307. else
  308. cat "$@"
  309. fi
  310. }
  311. o(){
  312. if test $# -eq 0
  313. then
  314. _open_file .
  315. else
  316. for f in "$@"
  317. do
  318. if test -d "$f"
  319. then
  320. _open_file "$f"
  321. else
  322. _open_file "$f"
  323. fi
  324. done
  325. fi
  326. }
  327. convmv-sjis2utf8-test(){
  328. convmv -r -f sjis -t utf8 *
  329. }
  330. convmv-sjis2utf8-notest(){
  331. convmv -r -f sjis -t utf8 * --notest
  332. }
  333. __my_parse_svn_branch() {
  334. local LANG=C
  335. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  336. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  337. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  338. }
  339. __my_svn_ps1(){
  340. if svn status >/dev/null 2>&1
  341. then
  342. local svn_branch=$(__my_parse_svn_branch)
  343. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  344. fi
  345. }
  346. #Change ANSI Colors
  347. _chengecolors(){
  348. echo -e \
  349. "\e]P0000000" \
  350. "\e]P1cd0000" \
  351. "\e]P200cd00" \
  352. "\e]P3cdcd00" \
  353. "\e]P41e90ff" \
  354. "\e]P5cd00cd" \
  355. "\e]P600cdcd" \
  356. "\e]P7353535" \
  357. "\e]P8666666" \
  358. "\e]P9ff9999" \
  359. "\e]Pa99ff99" \
  360. "\e]Pbffff99" \
  361. "\e]Pc9999ff" \
  362. "\e]Pdff99ff" \
  363. "\e]Pe99ffff" \
  364. "\e]Pfffffff"
  365. }
  366. # printf "\e]P7353535" \
  367. _colors(){
  368. echo -e \
  369. "\e[30mBlack" \
  370. "\e[31mRed" \
  371. "\e[32mGreen" \
  372. "\e[33mYellow" \
  373. "\e[34mBlue" \
  374. "\e[35mMagenta" \
  375. "\e[36mCyan" \
  376. "\e[37mWhite"
  377. echo -e \
  378. "\e[30;1mBright Black" \
  379. "\e[31;1mBright Red" \
  380. "\e[32;1mBright Green" \
  381. "\e[33;1mBright Yellow" \
  382. "\e[34;1mBright Blue" \
  383. "\e[35;1mBright Magenta" \
  384. "\e[36;1mBright Cyan" \
  385. "\e[37;1mBright White\n" \
  386. "\e[0m"
  387. }
  388. winln(){
  389. # for windose make link (actually junction)
  390. if test $# -eq 0
  391. then
  392. {
  393. echo "usage: winln TARGET LINK_NAME"
  394. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  395. echo "About other features run 'junction'."
  396. } 1>&2
  397. return 1
  398. else
  399. junction "$2" "$1"
  400. fi
  401. }
  402. __my_battery_status(){
  403. local dir=/sys/class/power_supply/BAT0
  404. if test -d $dir
  405. then
  406. local st=$(cat $dir/status)
  407. local full=$(cat $dir/charge_full)
  408. local now=$(cat $dir/charge_now)
  409. local rate=$(expr $now \* 100 / $full)
  410. printf "$1" "${st}:${rate}%"
  411. fi
  412. }
  413. alias bat='__my_battery_status %s\\n'
  414. ip-address(){
  415. test type ifconfig >/dev/null 2>&1 || return 1
  416. local ip=$(LANG=C ifconfig | \grep --color=never "inet " | \grep --color=never -v "127.0.0.1" | awk '{print $2}')
  417. test -n "$ip" && printf $1 $ip
  418. }
  419. __my_ps1_moc(){
  420. local last=$?
  421. __my_moc_state "[MOC:%s]"
  422. return $last
  423. }
  424. __my_ps1_git(){
  425. local last=$?
  426. __try_exec __git_ps1 "[GIT:$(__try_exec git config --get user.name):%s]"
  427. return $last
  428. }
  429. __my_ps1_ipaddr(){
  430. local last=$?
  431. test -z "$DISPLAY" && ! iswindows && ip-address [Addr:%s]
  432. return $last
  433. }
  434. __my_ps1_bttry(){
  435. local last=$?
  436. local bst="${TMP}/batterystatus"
  437. if test -z "$DISPLAY" && ! iswindows
  438. then
  439. test -f $bst && local bstr="$(cat $bst)"
  440. test -n "$bstr" && echo "[Battery:$bstr]"
  441. __my_battery_status %s >$bst &
  442. fi
  443. return $last
  444. }
  445. __my_ps1_dirs(){
  446. dirs | wc -l
  447. }
  448. __my_ps1_jobs(){
  449. jobs | wc -l
  450. }
  451. if test "$TERM" != dumb
  452. then
  453. __my_c1="\[\e[1;31m\]" # color for PWD
  454. __my_c2="\[\e[0;36m\]" # color for user
  455. __my_c3="\[\e[1;30m\]" # color for OLDPWD
  456. __my_c4="\[\e[1;32m\]" # color for ::
  457. __my_cdef="\[\e[0m\]"
  458. fi
  459. _PS1="\
  460. ${__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\
  461. ${__my_c4}:: ${__my_c2}\u@\H${__my_cdef} \D{%a, %d %b %Y %T %z} ${SHELL} \V\n\
  462. ${__my_c4}:: ${__my_cdef}shlv:${SHLVL} cnum:\# jobs:\j last:\$? \$ "
  463. PS1=$_PS1
  464. __my_set_title(){
  465. title="$(echo $@)"
  466. case $TERM in
  467. (rxvt*|xterm*|aterm|screen*)
  468. test -t 1 &&
  469. test -n "$DISPLAY" &&
  470. test -z "$EMACS" &&
  471. echo -n -e "\033]0;${title}\007"
  472. ;;
  473. esac
  474. }
  475. export PROMPT_COMMAND="__my_set_title \${USER}@\${HOSTNAME}\ \${PWD};"
  476. # copied from https://wiki.archlinux.org/index.php/X_resources
  477. invader(){
  478. # ANSI color scheme script featuring Space Invaders
  479. #
  480. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  481. # Modified by lolilolicon
  482. #
  483. f=3 b=4
  484. for j in f b; do
  485. for i in {0..7}; do
  486. printf -v $j$i %b "\e[${!j}${i}m"
  487. done
  488. done
  489. bld=$'\e[1m'
  490. rst=$'\e[0m'
  491. cat << EOF
  492. $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  493. $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  494. $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
  495. $f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst
  496. $bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  497. $bld$f1█▄█▀███▀█▄█ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4█▄█▀███▀█▄█ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  498. $bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst
  499. $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
  500. $f7▌$rst
  501. $f7▌$rst
  502. $f7 ▄█▄ $rst
  503. $f7▄█████████▄$rst
  504. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  505. EOF
  506. }
  507. #/etc/lsb-release