25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

495 lines
14 KiB

  1. #!/bin/bash
  2. ##########################
  3. # system type
  4. alias ismsys=false
  5. alias iscygwin=false
  6. alias iswindows="iscygwin || ismsys"
  7. alias isdarwin=false
  8. alias islinux=false
  9. case `uname` in
  10. (MINGW32*) alias ismsys=true ;;
  11. (CYGWIN*) alias iscygwin=true ;;
  12. (Darwin*) alias isdarwin=true ;;
  13. (Linux*) alias islinux=true ;;
  14. esac
  15. ##########################################
  16. null(){
  17. "$@" >/dev/null 2>&1
  18. }
  19. __try_exec(){
  20. type $1 >/dev/null 2>&1 && "$@"
  21. }
  22. export PS1="\$(__my_prompt_function)\$ "
  23. # PROMPT_COMMAND=prompt_function
  24. if false iswindows
  25. then
  26. export PAGER='tr -d \\r | less'
  27. else
  28. export PAGER="less"
  29. fi
  30. export LESS="-iRMX"
  31. if false null type vim
  32. then
  33. export EDITOR=vim
  34. else
  35. export EDITOR=vi
  36. fi
  37. export LC_MESSAGES=C
  38. # export CDPATH=".:~"
  39. export VISUAL="$EDITOR"
  40. export GIT_PAGER="$PAGER"
  41. export GIT_EDITOR="$EDITOR"
  42. null type stty && {
  43. stty stop undef # unbind C-s to stop displaying output
  44. stty erase '^h'
  45. }
  46. if iswindows; then
  47. # export TMP=/tmp
  48. # export TEMP=/tmp
  49. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  50. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  51. export USER=$USERNAME
  52. fi
  53. #######################
  54. uname -a
  55. echo TERM $TERM connected to $(tty), running $BASH $BASH_VERSION
  56. echo
  57. ###################################
  58. # some aliases and functions
  59. test "$TERM" == dumb || _coloroption=" --color=always"
  60. alias ls="ls -hCF --time-style=long-iso${_coloroption}"
  61. # export GREP_OPTIONS=""
  62. alias grep="grep -n${_coloroption}"
  63. # alias ll="ls -l"
  64. # alias la="ls -A"
  65. # alias lla="ls -Al"
  66. # alias less=""
  67. alias vl=/usr/share/vim/vimcurrent/macros/less.sh
  68. alias em="emacs -nw"
  69. alias pstree="LANG=C pstree"
  70. alias cp="cp -v"
  71. alias mv="mv -v"
  72. alias psall="ps auxww"
  73. alias q=exit
  74. alias p="$PAGER"
  75. alias c=cat
  76. alias e3=e3em
  77. alias dirs="dirs -v -l | \grep -v \$(printf '%s$' \$PWD)"
  78. alias po=popd
  79. alias pu=pushd
  80. alias sudo="sudo " # use aliases through sudo
  81. alias halt="sudo halt"
  82. alias reboot="sudo reboot"
  83. alias suspend="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  84. /org/freedesktop/UPower org.freedesktop.UPower.Suspend"
  85. alias hibernate="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  86. /org/freedesktop/UPower org.freedesktop.UPower.Hibernate"
  87. alias rand="echo \$RANDOM"
  88. alias ut="ssh 6365454829@un001.ecc.u-tokyo.ac.jp"
  89. alias xunp="file-roller -h"
  90. # alias pacome="sudo \paco -D"
  91. alias pcalc="python -i -c 'from math import *' "
  92. alias py3=python3
  93. alias py2=python2
  94. alias _reloadrc="test -f ~/.bashrc && source ~/.bashrc"
  95. # alias mytime="date +%Y%m%d-%H%M%S"
  96. alias sh="ENV=$HOME/.shrc PS1=\$\ sh"
  97. # type trash >/dev/null 2>&1 && alias rm=trash
  98. alias wicdc=wicd-curses
  99. alias aptin="apt-get install"
  100. alias aptsearch="apt-cache search"
  101. alias aptshow="apt-cache show"
  102. alias yt=yaourt
  103. null type pacman-color && {
  104. alias pacman=pacman-color
  105. export pacman_program=pacman-color # used by pacmatic
  106. export PACMAN=pacman-color # used by yaourt
  107. }
  108. null type pacmatic && {
  109. alias pacman="env pacman_program=${pacman_program} pacmatic"
  110. export PACMAN="env pacman_program=${pacman_program} pacmatic"
  111. }
  112. alias ubuntu-upgrade="sudo apt-get autoremove --yes && sudo apt-get update --yes && sudo apt-get upgrade --yes"
  113. alias arch-upgrade="sudo pacman -Syu"
  114. alias port-upgrade="port selfupdate && port sync && port upgrade installed"
  115. if iscygwin; then
  116. null type windate || alias windate="/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%'"
  117. alias cygsu="cygstart /cygwinsetup.exe"
  118. alias emacs="CYGWIN=tty emacs -nw"
  119. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto)"
  120. fi
  121. alias g=git
  122. if null type _git # enable programmable completion for g
  123. then
  124. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  125. || complete -o default -o nospace -F _git g
  126. fi
  127. showinfo(){
  128. echo "Japanese letters are 表示可能"
  129. __try_exec diskinfo
  130. ! isdarwin && test -n "${DISPLAY}" && {
  131. __try_exec xrandr | \grep --color=never ^Screen
  132. }
  133. iswindows || __try_exec finger $USER
  134. LANG=C __try_exec id
  135. __try_exec xset q
  136. }
  137. x(){
  138. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  139. #nohup startx >~/.backup/log/xorg.log 2>&1 &
  140. startx
  141. else
  142. echo "X cant be started! Maybe another X is already running!" 1>&2
  143. fi
  144. }
  145. bak(){
  146. for file in "$@"
  147. do
  148. cp -v ${file} ${file}.bak
  149. done
  150. }
  151. di(){
  152. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  153. then
  154. local diffcmd=colordiff
  155. else
  156. local diffcmd=diff
  157. fi
  158. ${diffcmd} -u "$@" | ${PAGER}
  159. }
  160. throw-away(){
  161. mkdir -p ~/.backup/tb
  162. for file in "$@"
  163. do
  164. mv $file ~/.backup/tb
  165. done
  166. }
  167. mkcd(){
  168. mkdir -p $1
  169. cd $1
  170. }
  171. catclip(){
  172. if iswindows
  173. then
  174. cat /dev/clipboard | tr -d \\r
  175. else
  176. xclip -o -selection "clipboard"
  177. fi
  178. }
  179. setclip(){
  180. if iswindows
  181. then
  182. if test $# -eq 0
  183. then
  184. sed -e 's/$/\r/' | tee /dev/clipboard
  185. else
  186. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  187. fi
  188. else
  189. if test $# -eq 0
  190. then
  191. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  192. else
  193. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  194. fi
  195. fi
  196. }
  197. if iswindows; then
  198. alias _open_file='cmd.exe //c start ""'
  199. elif isdarwin; then
  200. alias _open_file=open
  201. elif islinux; then
  202. if null type pcmanfm; then
  203. alias _open_file="LC_MESSAGES= pcmanfm"
  204. else
  205. alias _open_file="LC_MESSAGES= xdg-open"
  206. fi
  207. else
  208. alias _open_file=cat
  209. fi
  210. o(){
  211. if test $# -eq 0
  212. then
  213. _open_file . &
  214. else
  215. for f in "$@"
  216. do
  217. if test -d $f
  218. then
  219. _open_file $f &
  220. else
  221. _open_file $f
  222. fi
  223. done
  224. fi
  225. }
  226. convmv-sjis2utf8-test(){
  227. convmv -r -f sjis -t utf8 *
  228. }
  229. convmv-sjis2utf8-notest(){
  230. convmv -r -f sjis -t utf8 * --notest
  231. }
  232. _my_git_config(){
  233. git config --global user.name '10sr'
  234. git config --global user.email '8slashes+git@gmail.com'
  235. git config --global core.autocrlf false
  236. git config --global core.excludesfile '~/.gitignore'
  237. git config --global color.ui auto
  238. git config --global status.relativePaths false
  239. git config --global status.showUntrackedFiles normal
  240. git config --global alias.graph "log --graph --date-order -C -M --pretty=tformat:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  241. git config --global alias.st "status -s"
  242. git config --global alias.b "branch"
  243. git config --global alias.ci "commit --verbose"
  244. git config --global alias.co "checkout"
  245. git config --global alias.cim "commit --verbose -m"
  246. git config --global alias.di "diff --color"
  247. git config --global alias.me "merge --no-ff --stat -v"
  248. git config --global alias.ls "ls-files -v --full-name"
  249. git config --global alias.sl "!sl"
  250. # git config --global alias.my-ls "ls-files | xargs ls"
  251. # git config --global alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  252. git config --global alias.addi "add -i"
  253. if iswindows; then
  254. git config --global core.fileMode false
  255. fi
  256. }
  257. __my_parse_svn_branch() {
  258. local LANG=C
  259. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  260. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  261. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  262. }
  263. __my_svn_ps1(){
  264. if svn status >/dev/null 2>&1
  265. then
  266. local svn_branch=$(__my_parse_svn_branch)
  267. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  268. fi
  269. }
  270. #Change ANSI Colors
  271. _chengecolors(){
  272. echo -e \
  273. "\e]P0000000" \
  274. "\e]P1cd0000" \
  275. "\e]P200cd00" \
  276. "\e]P3cdcd00" \
  277. "\e]P41e90ff" \
  278. "\e]P5cd00cd" \
  279. "\e]P600cdcd" \
  280. "\e]P7353535" \
  281. "\e]P8666666" \
  282. "\e]P9ff9999" \
  283. "\e]Pa99ff99" \
  284. "\e]Pbffff99" \
  285. "\e]Pc9999ff" \
  286. "\e]Pdff99ff" \
  287. "\e]Pe99ffff" \
  288. "\e]Pfffffff"
  289. }
  290. # printf "\e]P7353535" \
  291. _colors(){
  292. echo -e \
  293. "\e[30mBlack" \
  294. "\e[31mRed" \
  295. "\e[32mGreen" \
  296. "\e[33mYellow" \
  297. "\e[34mBlue" \
  298. "\e[35mMagenta" \
  299. "\e[36mCyan" \
  300. "\e[37mWhite"
  301. echo -e \
  302. "\e[30;1mBright Black" \
  303. "\e[31;1mBright Red" \
  304. "\e[32;1mBright Green" \
  305. "\e[33;1mBright Yellow" \
  306. "\e[34;1mBright Blue" \
  307. "\e[35;1mBright Magenta" \
  308. "\e[36;1mBright Cyan" \
  309. "\e[37;1mBright White\n" \
  310. "\e[0m"
  311. }
  312. _my_install_script(){
  313. mkdir -p $HOMO/bin/
  314. for f in "$@"
  315. do
  316. bn=$(basename "$f")
  317. type ${bn} >/dev/null 2>&1 || {
  318. wget "$f" -P "$HOME/bin/"
  319. chmod u+x "$HOME/bin/${bn}"
  320. }
  321. done
  322. }
  323. _my_install_script http://www.frexx.de/xterm-256-notes/data/colortable16.sh
  324. winln(){
  325. # for windose make link (actually junction)
  326. if test $# -eq 0
  327. then
  328. {
  329. echo "usage: winln TARGET LINK_NAME"
  330. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  331. echo "About other features run 'junction'."
  332. } 1>&2
  333. return 1
  334. else
  335. junction "$2" "$1"
  336. fi
  337. }
  338. __my_battery_status(){
  339. local dir=/sys/class/power_supply/BAT0
  340. if test -d $dir
  341. then
  342. local st=$(cat $dir/status)
  343. local full=$(cat $dir/charge_full)
  344. local now=$(cat $dir/charge_now)
  345. local rate=$(expr $now \* 100 / $full)
  346. printf "$1" "${st}:${rate}%"
  347. fi
  348. }
  349. alias bat='__my_battery_status %s\\n'
  350. ip-address(){
  351. local ip=$(LANG=C ifconfig | \grep --color=never "inet " | \grep --color=never -v "127.0.0.1" | awk '{print $2}')
  352. test -n "$ip" && printf $1 $ip
  353. }
  354. __my_prompt_function(){ # used by PS1
  355. # remove __try_exec from function
  356. local lastreturn=$?
  357. if test "${TERM}" == dumb
  358. then
  359. local c1=
  360. local c2=
  361. local c3=
  362. local cdef=
  363. else
  364. local c1="\e[33m"
  365. local c2="\e[36m"
  366. local c3="\e[37m"
  367. local cdef="\e[0m"
  368. fi
  369. if iswindows
  370. then
  371. local pwd=$PWD
  372. local oldpwd=$OLDPWD
  373. git branch >/dev/null 2>&1 && local git="[GIT]"
  374. local date=$(/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%')
  375. else
  376. local pwd=$(echo "${PWD}/" | sed -e "s#${HOME}#~#")
  377. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s#${HOME}#~#")
  378. local jobnum=$(jobs | wc -l)
  379. local git=$(__try_exec __git_ps1 [GIT:%s])
  380. local date=$(LANG=C __try_exec date +"%a, %d %b %Y %T %z")
  381. fi
  382. local dirs=$(dirs | wc -l)
  383. # local svn=$(type svn >/dev/null 2>&1 && __try_exec __my_svn_ps1 [SVN:%s])
  384. if test -z "$DISPLAY"
  385. then
  386. local ip=$(ip-address [Addr:%s])
  387. local bst="/tmp/${USER}-tmp/batterystatus"
  388. test -f $bst && local battery="[Battery:$(sed -e 's`%`%%`g' $bst)]"
  389. __my_battery_status %s >$bst &
  390. fi
  391. # local battery=$(battery-state [%s] | sed -e 's`%`%%`g') # very slow
  392. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}${battery}${ip}\n"
  393. printf "${c2}${USER}@${HOSTNAME}${cdef} ${date}\n"
  394. printf "shlv:${SHLVL} jobs:${jobnum} dirs:${dirs} last:${lastreturn} "
  395. }
  396. __my_set_title(){
  397. title="$(echo $@)"
  398. case $TERM in
  399. (rxvt*|xterm*|aterm)
  400. test -t 1 &&
  401. test -n "$DISPLAY" &&
  402. test -z "$EMACS" &&
  403. echo -n -e "\033]0;${1}\007"
  404. ;;
  405. esac
  406. }
  407. PROMPT_COMMAND="__my_set_title \${USER}@\${HOSTNAME}\ \${PWD};${PROMPT_COMMAND}"
  408. # copied from https://wiki.archlinux.org/index.php/X_resources
  409. invader(){
  410. # ANSI color scheme script featuring Space Invaders
  411. #
  412. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  413. # Modified by lolilolicon
  414. #
  415. f=3 b=4
  416. for j in f b; do
  417. for i in {0..7}; do
  418. printf -v $j$i %b "\e[${!j}${i}m"
  419. done
  420. done
  421. bld=$'\e[1m'
  422. rst=$'\e[0m'
  423. cat << EOF
  424. $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  425. $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  426. $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
  427. $f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst
  428. $bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  429. $bld$f1█▄█▀███▀█▄█ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4█▄█▀███▀█▄█ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  430. $bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst
  431. $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
  432. $f7▌$rst
  433. $f7▌$rst
  434. $f7 ▄█▄ $rst
  435. $f7▄█████████▄$rst
  436. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  437. EOF
  438. }