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.

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