No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

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