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.
 
 
 
 
 
 

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