25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

406 satır
10 KiB

  1. #!/bin/bash
  2. ##########################
  3. # system type
  4. alias ismsys=false
  5. alias iscygwin=false
  6. alias isdarwin=false
  7. alias iswindows="iscygwin || ismsys"
  8. alias islinux="! iswindows && ! isdarwin" # i havent used unix yet
  9. case `uname` in
  10. (MINGW32*) alias ismsys=true ;;
  11. (CYGWIN*) alias iscygwin=true ;;
  12. (Darwin*) alias isdarwin=true ;;
  13. esac
  14. ##########################################
  15. null(){
  16. "$@" >/dev/null 2>&1
  17. }
  18. __try_exec(){
  19. type $1 >/dev/null 2>&1 && "$@"
  20. }
  21. export PS1="\$(__my_prompt_function)\$ "
  22. # PROMPT_COMMAND=prompt_function
  23. if false # iswindows
  24. then
  25. export PAGER='tr -d \\r | less'
  26. else
  27. export PAGER="less"
  28. fi
  29. if null type vim
  30. then
  31. export EDITOR=vim
  32. else
  33. export EDITOR=vi
  34. fi
  35. export VISUAL="$EDITOR"
  36. export LESS="-iRMX"
  37. export LC_MESSAGES=C
  38. export CDPATH=".:~"
  39. export GIT_PAGER="$PAGER"
  40. export GIT_EDITOR="$EDITOR"
  41. null type stty && {
  42. stty stop undef # unbind C-s to stop displaying output
  43. stty erase '^h'
  44. }
  45. if iswindows; then
  46. # export TMP=/tmp
  47. # export TEMP=/tmp
  48. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  49. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  50. export USER=$USERNAME
  51. fi
  52. #######################
  53. uname -a
  54. if [ "${EMACS}" = "t" ]; then # for emacs shell
  55. true export PS1="\u@\H \d \t \w\nemacs shell\$ "
  56. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # for emacs term
  57. echo "Emacs Term"
  58. fi
  59. if test -f /etc/issue
  60. then
  61. cat /etc/issue
  62. fi
  63. ###################################
  64. # some aliases and functions
  65. alias ls="ls -hCFG $(test "$TERM" == dumb || echo --color=auto\ )--time-style=long-iso"
  66. # alias ll="ls -l"
  67. # alias la="ls -A"
  68. # alias lla="ls -Al"
  69. # alias less=""
  70. alias vl=/usr/share/vim/vimcurrent/macros/less.sh
  71. alias em="emacs -nw"
  72. # alias apt-get="sudo apt-get"
  73. alias ut="ssh 6365454829@un001.ecc.u-tokyo.ac.jp"
  74. alias rand="echo \$RANDOM"
  75. alias xunp="file-roller -h"
  76. alias pacome="sudo \paco -D"
  77. alias psall="ps auxww"
  78. alias q=exit
  79. alias p="$PAGER"
  80. alias c=cat
  81. alias pcalc="python -i -c 'from math import *' "
  82. alias py3=python3
  83. alias _reloadrc="test -f ~/.bashrc && source ~/.bashrc"
  84. alias sudo="sudo " # use aliases through sudo
  85. alias e3=e3em
  86. alias mytime="date +%Y%m%d-%H%M%S"
  87. alias sh="ENV=$HOME/.shrc PS1=\$\ sh"
  88. alias halt="sudo halt"
  89. alias reboot="sudo reboot"
  90. # type trash >/dev/null 2>&1 && alias rm=trash
  91. alias aptin="apt-get install"
  92. alias aptsearch="apt-cache search"
  93. alias aptshow="apt-cache show"
  94. alias yt=yaourt
  95. export PACMAN=pacman-color
  96. alias ubuntu-upgrade="sudo apt-get autoremove --yes && sudo apt-get update --yes && sudo apt-get upgrade --yes"
  97. alias arch-upgrade="yaourt -Syu"
  98. alias port-upgrade="port selfupdate && port sync && port upgrade installed"
  99. if iscygwin; then
  100. null type windate || alias windate="/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%'"
  101. alias cygsu="cygstart /cygwinsetup.exe"
  102. alias emacs="CYGWIN=tty emacs -nw"
  103. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto)"
  104. fi
  105. alias g=git
  106. if null type _git # enable programmable completion for g
  107. then
  108. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  109. || complete -o default -o nospace -F _git g
  110. fi
  111. showinfo(){
  112. echo "Japanese letters are 表示可能"
  113. __try_exec diskinfo
  114. ! isdarwin && test -n "${DISPLAY}" && {
  115. __try_exec xrandr | grep --color=never ^Screen
  116. }
  117. iswindows || __try_exec finger $USER
  118. LANG=C __try_exec id
  119. __try_exec xset q
  120. }
  121. export __MYGITBAREREP="${HOME}/dbx/.git-bare"
  122. git-make-local-rep(){
  123. test $# -eq 0 && {
  124. echo "specify repository name." 1>&2
  125. return 1
  126. }
  127. dir="${__MYGITBAREREP}/$1.git"
  128. cdir=$PWD
  129. if test -d "$dir"
  130. then
  131. echo "dir $dir already exist!" 1>&2
  132. else
  133. mkdir -p "$dir" && {
  134. cd "$dir" &&
  135. git init --bare --shared=all
  136. }
  137. fi
  138. cd ${cdir}
  139. }
  140. bak(){
  141. for file in "$@"
  142. do
  143. mv -v ${file} ${file}.bak
  144. done
  145. }
  146. di(){
  147. if null type colordiff && test $TERM != dumb
  148. then
  149. local diffcmd=colordiff
  150. else
  151. local diffcmd=diff
  152. fi
  153. ${diffcmd} -u "$@" | ${PAGER}
  154. }
  155. throw-away(){
  156. mkdir -p ~/.backup/tb
  157. for file in "$@"
  158. do
  159. mv $file ~/.backup/tb
  160. done
  161. }
  162. mkcd(){
  163. mkdir -p $1
  164. cd $1
  165. }
  166. catclip(){
  167. if iswindows
  168. then
  169. cat /dev/clipboard | tr -d \\r
  170. else
  171. xclip -o -selection "clipboard"
  172. fi
  173. }
  174. setclip(){
  175. if iswindows
  176. then
  177. if test $# -eq 0
  178. then
  179. sed -e 's/$/\r/' | tee /dev/clipboard
  180. else
  181. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  182. fi
  183. else
  184. if test $# -eq 0
  185. then
  186. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  187. else
  188. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  189. fi
  190. fi
  191. }
  192. o(){
  193. if [ $# -eq 0 ]
  194. then
  195. local f=.
  196. else
  197. local f="$1"
  198. fi
  199. if iswindows
  200. then
  201. cmd.exe //c start "" "$f"
  202. elif isdarwin
  203. then
  204. open "$f"
  205. else
  206. xdg-open "$f"
  207. fi
  208. }
  209. convmv-sjis2utf8-test(){
  210. convmv -r -f sjis -t utf8 *
  211. }
  212. convmv-sjis2utf8-notest(){
  213. convmv -r -f sjis -t utf8 * --notest
  214. }
  215. _mygitconfig(){
  216. git config --global user.name '10sr'
  217. git config --global user.email '8slashes+git@gmail.com'
  218. git config --global core.autocrlf false
  219. git config --global color.ui auto
  220. git config --global status.relativePaths false
  221. git config --global status.showUntrackedFiles normal
  222. git config --global alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  223. git config --global alias.st "status -s"
  224. git config --global alias.b "branch"
  225. git config --global alias.ci "commit --verbose"
  226. git config --global alias.co "checkout"
  227. git config --global alias.cim "commit --verbose -m"
  228. git config --global alias.di "diff --color"
  229. git config --global alias.me "merge --no-ff --stat -v"
  230. git config --global alias.ls "ls-files -v --full-name"
  231. git config --global alias.sl "!sl"
  232. # git config --global alias.my-ls "ls-files | xargs ls"
  233. # git config --global alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  234. git config --global alias.addi "add -i"
  235. if iswindows; then
  236. git config --global core.fileMode false
  237. fi
  238. }
  239. __my_parse_svn_branch() {
  240. local LANG=C
  241. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  242. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  243. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  244. }
  245. __my_svn_ps1(){
  246. local svn_branch=$(__my_parse_svn_branch)
  247. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  248. }
  249. __my_prompt_function(){ # used by PS1
  250. local lastreturn=$?
  251. if test "${TERM}" == dumb
  252. then
  253. local c1=
  254. local c2=
  255. local c3=
  256. local cdef=
  257. else
  258. local c1="\e[33m"
  259. local c2="\e[36m"
  260. local c3="\e[37m"
  261. local cdef="\e[0m"
  262. fi
  263. if iswindows
  264. then
  265. local pwd=$PWD
  266. local oldpwd=$OLDPWD
  267. local jobnum=
  268. if git branch >/dev/null 2>&1
  269. then
  270. local git="[GIT]"
  271. else
  272. local git=
  273. fi
  274. local date=$(/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%')
  275. else
  276. local pwd=$(echo "${PWD}/" | sed -e "s#${HOME}#~#")
  277. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s#${HOME}#~#")
  278. local jobnum=$(jobs | wc -l)
  279. local git=$(__try_exec __git_ps1 [GIT:%s])
  280. local date=$(LANG=C __try_exec date +"%a, %d %b %Y %T %z")
  281. fi
  282. local svn=$(type svn >/dev/null 2>&1 && __try_exec __my_svn_ps1 [SVN:%s])
  283. test -f ~/.batterystatus && local battery="[Battery:$(cat ~/.batterystatus | sed -e 's`%`%%`g')]"
  284. local ip=$(ip-address [Addr:%s])
  285. # local battery=$(battery-state [%s] | sed -e 's`%`%%`g') # very slow
  286. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}${battery}${ip}\n"
  287. printf "${c2}${USER}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n"
  288. printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} "
  289. }
  290. #Change ANSI Colors
  291. _chengecolors(){
  292. echo -e \
  293. "\e]P0000000" \
  294. "\e]P1cd0000" \
  295. "\e]P200cd00" \
  296. "\e]P3cdcd00" \
  297. "\e]P41e90ff" \
  298. "\e]P5cd00cd" \
  299. "\e]P600cdcd" \
  300. "\e]P7353535" \
  301. "\e]P8666666" \
  302. "\e]P9ff9999" \
  303. "\e]Pa99ff99" \
  304. "\e]Pbffff99" \
  305. "\e]Pc9999ff" \
  306. "\e]Pdff99ff" \
  307. "\e]Pe99ffff" \
  308. "\e]Pfffffff"
  309. }
  310. # printf "\e]P7353535" \
  311. _echocolors(){
  312. echo -e \
  313. "\e[30mBlack\n" \
  314. "\e[31mRed\n" \
  315. "\e[32mGreen\n" \
  316. "\e[33mYellow\n" \
  317. "\e[34mBlue\n" \
  318. "\e[35mMagenta\n" \
  319. "\e[36mCyan\n" \
  320. "\e[37mWhite\n" \
  321. "\e[30;1mBright Black\n" \
  322. "\e[31;1mBright Red\n" \
  323. "\e[32;1mBright Green\n" \
  324. "\e[33;1mBright Yellow\n" \
  325. "\e[34;1mBright Blue\n" \
  326. "\e[35;1mBright Magenta\n" \
  327. "\e[36;1mBright Cyan\n" \
  328. "\e[37;1mBright White\n" \
  329. "\e[0m"
  330. }
  331. # http://myminios.googlecode.com/svn-history/r10/trunk/colortable16.sh
  332. winln(){
  333. # for windose make link (actually junction)
  334. if test $# -eq 0
  335. then
  336. {
  337. echo "usage: winln TARGET LINK_NAME"
  338. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  339. echo "About other features run 'junction'."
  340. } 1>&2
  341. return 1
  342. else
  343. junction "$2" "$1"
  344. fi
  345. }
  346. battery-status(){
  347. local dir=/sys/class/power_supply/BAT0
  348. if test -d $dir
  349. then
  350. local st=$(cat $dir/status)
  351. local full=$(cat $dir/charge_full)
  352. local now=$(cat $dir/charge_now)
  353. local rate=$(expr $now \* 100 / $full)
  354. printf $1 "${st}:${rate}%"
  355. fi
  356. }
  357. alias bat='battery-status %s\\n'
  358. battery-status2(){
  359. local dir=/sys/class/power_supply/BAT0
  360. . $dir/uevent
  361. local rate=$(expr $POWER_SUPPLY_CHARGE_NOW \* 100 / $POWER_SUPPLY_CHARGE_FULL)
  362. echo ${POWER_SUPPLY_STATUS}:${rate}%
  363. }
  364. ip-address(){
  365. local ip=$(LANG=C ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}')
  366. test -n "$ip" && printf $1 $ip
  367. }