You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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