Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

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