Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

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