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ů.
 
 
 
 
 
 

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