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

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