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.
 
 
 
 
 
 

502 Zeilen
14 KiB

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