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.
 
 
 
 
 
 

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