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.
 
 
 
 
 
 

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