Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

471 wiersze
13 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 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. }