Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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