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.
 
 
 
 
 
 

595 linhas
15 KiB

  1. #!/bin/bash
  2. # If not running interactively, don't do anything
  3. [[ $- != *i* ]] && 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]*" # do not use
  79. alias ls="ls -hCF${_coloroption}${_timeoption}"
  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. mcrypt-stream(){
  192. test $# -eq 2 || return 1
  193. case $1 in
  194. en)
  195. mcrypt --key $2 | base64 ;;
  196. de)
  197. base64 -d | mcrypt -d --key $2 ;;
  198. esac
  199. }
  200. gpg-stream(){
  201. test $# -eq 2 || return 1
  202. case $1 in
  203. en)
  204. gpg --passphrase $2 -c --batch |base64 ;;
  205. de)
  206. base64 -d|gpg --passphrase $2 -d --batch ;;
  207. esac
  208. }
  209. alias enst="gpg-stream en"
  210. alias dest="gpg-stream de"
  211. showinfo(){
  212. echo "Japanese letters are 表示可能"
  213. __try_exec diskinfo
  214. ! isdarwin && test -n "${DISPLAY}" && {
  215. __try_exec xrandr | \grep --color=never ^Screen
  216. }
  217. iswindows || __try_exec finger $USER
  218. LANG=C __try_exec id
  219. __try_exec xset q
  220. }
  221. x(){
  222. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  223. #mkdir -p ~/.my/log
  224. # nohup startx >~/.my/log/xorg.log 2>&1 &
  225. # exit
  226. exec startx
  227. else
  228. echo "X cant be started! Maybe another X is already running or something." 1>&2
  229. fi
  230. }
  231. bak(){
  232. for file in "$@"
  233. do
  234. cp -v ${file} ${file}.bak
  235. done
  236. }
  237. di(){
  238. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  239. then
  240. local diffcmd=colordiff
  241. else
  242. local diffcmd=diff
  243. fi
  244. ${diffcmd} -u "$@" | ${PAGER}
  245. }
  246. tb(){
  247. local tb=~/.my/tb
  248. mkdir -p $tb
  249. for file in "$@"
  250. do
  251. mv $file $tb
  252. done
  253. }
  254. mkcd(){
  255. mkdir -p $1
  256. cd $1
  257. }
  258. catclip(){
  259. if iswindows
  260. then
  261. cat /dev/clipboard | tr -d \\r
  262. elif isdarwin
  263. then
  264. pbpaste
  265. else
  266. xclip -o -selection "clipboard"
  267. fi
  268. }
  269. setclip(){
  270. if iswindows
  271. then
  272. if test $# -eq 0
  273. then
  274. sed -e 's/$/\r/' | tee /dev/clipboard
  275. else
  276. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  277. fi
  278. elif isdarwin
  279. then
  280. if test $# -eq 0
  281. then
  282. pbcopy
  283. else
  284. cat "$@" | pbcopy
  285. fi
  286. else
  287. if test $# -eq 0
  288. then
  289. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  290. else
  291. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  292. fi
  293. fi
  294. }
  295. open_file(){
  296. if iswindows
  297. then
  298. cmd.exe //c start "" "$@"
  299. elif isdarwin
  300. then
  301. touch "$@"
  302. open "$@"
  303. elif islinux
  304. then
  305. if null type pcmanfm; then
  306. LC_MESSAGES= pcmanfm "$@"
  307. else
  308. LC_MESSAGES= xdg-open "$@" &
  309. fi
  310. else
  311. cat "$@"
  312. fi
  313. }
  314. o(){
  315. if test $# -eq 0
  316. then
  317. open_file .
  318. else
  319. for f in "$@"
  320. do
  321. open_file "$f"
  322. done
  323. fi
  324. }
  325. convmv-sjis2utf8-test(){
  326. convmv -r -f sjis -t utf8 *
  327. }
  328. convmv-sjis2utf8-notest(){
  329. convmv -r -f sjis -t utf8 * --notest
  330. }
  331. __my_moc_state(){
  332. type mocp >/dev/null 2>&1 || return
  333. test "`mocp -Q %state 2>/dev/null`" == PLAY || return
  334. printf "$1" "`mocp -Q %title 2>/dev/null`"
  335. }
  336. __my_parse_svn_branch() {
  337. local LANG=C
  338. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  339. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  340. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  341. }
  342. __my_svn_ps1(){
  343. if svn status >/dev/null 2>&1
  344. then
  345. local svn_branch=$(__my_parse_svn_branch)
  346. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  347. fi
  348. }
  349. #Change ANSI Colors
  350. _chengecolors(){
  351. echo -e \
  352. "\e]P0000000" \
  353. "\e]P1cd0000" \
  354. "\e]P200cd00" \
  355. "\e]P3cdcd00" \
  356. "\e]P41e90ff" \
  357. "\e]P5cd00cd" \
  358. "\e]P600cdcd" \
  359. "\e]P7353535" \
  360. "\e]P8666666" \
  361. "\e]P9ff9999" \
  362. "\e]Pa99ff99" \
  363. "\e]Pbffff99" \
  364. "\e]Pc9999ff" \
  365. "\e]Pdff99ff" \
  366. "\e]Pe99ffff" \
  367. "\e]Pfffffff"
  368. }
  369. # printf "\e]P7353535" \
  370. _colors(){
  371. echo -e \
  372. "\e[30mBlack" \
  373. "\e[31mRed" \
  374. "\e[32mGreen" \
  375. "\e[33mYellow" \
  376. "\e[34mBlue" \
  377. "\e[35mMagenta" \
  378. "\e[36mCyan" \
  379. "\e[37mWhite"
  380. echo -e \
  381. "\e[30;1mBright Black" \
  382. "\e[31;1mBright Red" \
  383. "\e[32;1mBright Green" \
  384. "\e[33;1mBright Yellow" \
  385. "\e[34;1mBright Blue" \
  386. "\e[35;1mBright Magenta" \
  387. "\e[36;1mBright Cyan" \
  388. "\e[37;1mBright White\n" \
  389. "\e[0m"
  390. }
  391. winln(){
  392. # for windose make link (actually junction)
  393. if test $# -eq 0
  394. then
  395. {
  396. echo "usage: winln TARGET LINK_NAME"
  397. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  398. echo "About other features run 'junction'."
  399. } 1>&2
  400. return 1
  401. else
  402. junction "$2" "$1"
  403. fi
  404. }
  405. __my_battery_status(){
  406. local dir=/sys/class/power_supply/BAT0
  407. if test -d $dir
  408. then
  409. local st=$(cat $dir/status)
  410. local full=$(cat $dir/charge_full)
  411. local now=$(cat $dir/charge_now)
  412. local rate=$(expr $now \* 100 / $full)
  413. printf "$1" "${st}:${rate}%"
  414. fi
  415. }
  416. alias bat='__my_battery_status %s\\n'
  417. ip-address(){
  418. test type ifconfig >/dev/null 2>&1 || return 1
  419. local ip=$(LANG=C ifconfig | \grep --color=never "inet " | \grep --color=never -v "127.0.0.1" | awk '{print $2}')
  420. test -n "$ip" && printf $1 $ip
  421. }
  422. __my_ps1_scale(){
  423. local last=$?
  424. echo "[LC:${LINES}x${COLUMNS}]"
  425. return $last
  426. }
  427. __my_ps1_tmux(){
  428. local last=$?
  429. local tmuxc="$(__try_exec tmux display -p '#S:#I:#W.#P' 2>/dev/null)"
  430. test -n "$TMUX" && echo "[TMUX:$tmuxc]"
  431. return $last
  432. }
  433. __my_ps1_moc(){
  434. local last=$?
  435. __my_moc_state "[MOC:%s]"
  436. return $last
  437. }
  438. test -r /usr/share/git/git-prompt.sh && . /usr/share/git/git-prompt.sh
  439. __my_ps1_git(){
  440. local last=$?
  441. null type __git_ps1 || return $last
  442. __try_exec __git_ps1 "[GIT:$(__try_exec git config --get user.name):%s]"
  443. return $last
  444. }
  445. __my_ps1_ipaddr(){
  446. local last=$?
  447. test -z "$DISPLAY" && ! iswindows && ip-address [Addr:%s]
  448. return $last
  449. }
  450. __my_ps1_bttry(){
  451. local last=$?
  452. local bst="${TMP}/batterystatus"
  453. if test -z "$DISPLAY" && ! iswindows
  454. then
  455. test -f $bst && local bstr="$(cat $bst)"
  456. test -n "$bstr" && echo "[Battery:$bstr]"
  457. __my_battery_status %s >$bst &
  458. fi
  459. return $last
  460. }
  461. __my_ps1_dirs(){
  462. dirs | wc -l
  463. }
  464. __my_ps1_jobs(){
  465. jobs | wc -l
  466. }
  467. if test "$TERM" != dumb
  468. then
  469. __my_c1="\[\e[1;31m\]" # color for PWD
  470. __my_c2="\[\e[0;36m\]" # color for user
  471. __my_c3="\[\e[1;30m\]" # color for OLDPWD
  472. if test "`hostname`" = arch-aspireone; then __my_c4="\[\e[1;34m\]"
  473. elif test "`hostname`" = darwin-mba.local; then __my_c4="\[\e[1;33m\]"
  474. elif test "`hostname`" = newkiwi; then __my_c4="\[\e[1;35m\]"
  475. else __my_c4="\[\e[1;32m\]" # color for ::
  476. fi
  477. __my_cdef="\[\e[0m\]"
  478. fi
  479. _PS1="\
  480. ${__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\
  481. ${__my_c4}:: ${__my_c2}\u@\H${__my_cdef} \D{%a, %d %b %Y %T %z} ${SHELL} \V\n\
  482. ${__my_c4}:: ${__my_cdef}shlv:${SHLVL} cnum:\# jobs:\j last:\$? \$ "
  483. PS1=$_PS1
  484. __my_set_title(){
  485. title="$(echo $@)"
  486. case $TERM in
  487. (rxvt*|xterm*|aterm|screen*)
  488. test -t 1 &&
  489. test -n "$DISPLAY" &&
  490. test -z "$EMACS" &&
  491. echo -n -e "\033]0;${title}\007"
  492. ;;
  493. esac
  494. }
  495. export PROMPT_COMMAND="__my_set_title \${USER}@\${HOSTNAME}\ \${PWD}"
  496. # copied from https://wiki.archlinux.org/index.php/X_resources
  497. invader(){
  498. # ANSI color scheme script featuring Space Invaders
  499. #
  500. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  501. # Modified by lolilolicon
  502. #
  503. f=3 b=4
  504. for j in f b; do
  505. for i in {0..7}; do
  506. printf -v $j$i %b "\e[${!j}${i}m"
  507. done
  508. done
  509. bld=$'\e[1m'
  510. rst=$'\e[0m'
  511. cat << EOF
  512. $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  513. $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  514. $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
  515. $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. $bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst
  519. $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
  520. $f7▌$rst
  521. $f7▌$rst
  522. $f7 ▄█▄ $rst
  523. $f7▄█████████▄$rst
  524. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  525. EOF
  526. }
  527. #/etc/lsb-release