Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

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