Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

593 rindas
15 KiB

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