Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

485 rindas
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. 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. if [ "${EMACS}" = "t" ]; then # for emacs shell
  55. true export PS1="\u@\H \d \t \w\nemacs shell\$ "
  56. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # for emacs term
  57. echo "Emacs Term"
  58. fi
  59. # if test -f /etc/issue
  60. # then
  61. # cat /etc/issue
  62. # fi
  63. ###################################
  64. # some aliases and functions
  65. test "$TERM" == dumb || _ENABLECOLOR="--color=always "
  66. export LESS="-iRMX"
  67. export GREP_OPTIONS="${_ENABLECOLOR}"
  68. alias ls="ls -hCF ${_ENABLECOLOR}--time-style=long-iso"
  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 apt-get="sudo apt-get"
  77. alias ut="ssh 6365454829@un001.ecc.u-tokyo.ac.jp"
  78. alias rand="echo \$RANDOM"
  79. alias xunp="file-roller -h"
  80. alias pacome="sudo \paco -D"
  81. alias psall="ps auxww"
  82. alias q=exit
  83. alias p="$PAGER"
  84. alias c=cat
  85. alias pcalc="python -i -c 'from math import *' "
  86. alias py3=python3
  87. alias _reloadrc="test -f ~/.bashrc && source ~/.bashrc"
  88. alias sudo="sudo " # use aliases through sudo
  89. alias e3=e3em
  90. alias mytime="date +%Y%m%d-%H%M%S"
  91. alias sh="ENV=$HOME/.shrc PS1=\$\ sh"
  92. alias halt="sudo halt"
  93. alias reboot="sudo reboot"
  94. # type trash >/dev/null 2>&1 && alias rm=trash
  95. alias aptin="apt-get install"
  96. alias aptsearch="apt-cache search"
  97. alias aptshow="apt-cache show"
  98. alias yt=yaourt
  99. null type pacman-color && {
  100. alias pacman=pacman-color
  101. export pacman_program=pacman-color # used by pacmatic
  102. export PACMAN=pacman-color # used by yaourt
  103. }
  104. null type pacmatic && {
  105. alias pacman=pacmatic
  106. export PACMAN=pacmatic
  107. }
  108. alias ubuntu-upgrade="sudo apt-get autoremove --yes && sudo apt-get update --yes && sudo apt-get upgrade --yes"
  109. alias arch-upgrade="yaourt -Syu"
  110. alias port-upgrade="port selfupdate && port sync && port upgrade installed"
  111. if iscygwin; then
  112. null type windate || alias windate="/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%'"
  113. alias cygsu="cygstart /cygwinsetup.exe"
  114. alias emacs="CYGWIN=tty emacs -nw"
  115. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto)"
  116. fi
  117. alias g=git
  118. if null type _git # enable programmable completion for g
  119. then
  120. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  121. || complete -o default -o nospace -F _git g
  122. fi
  123. showinfo(){
  124. echo "Japanese letters are 表示可能"
  125. __try_exec diskinfo
  126. ! isdarwin && test -n "${DISPLAY}" && {
  127. __try_exec xrandr | grep --color=never ^Screen
  128. }
  129. iswindows || __try_exec finger $USER
  130. LANG=C __try_exec id
  131. __try_exec xset q
  132. }
  133. x(){
  134. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  135. nohup startx >~/.backup/log/xorg.log 2>&1 &
  136. else
  137. echo "X cant be started! Maybe another X is already running!" 1>&2
  138. fi
  139. }
  140. export __MYGITBAREREP="${HOME}/dbx/.git-bare"
  141. git-make-local-rep(){
  142. test $# -eq 0 && {
  143. echo "specify repository name." 1>&2
  144. return 1
  145. }
  146. dir="${__MYGITBAREREP}/$1.git"
  147. cdir=$PWD
  148. if test -d "$dir"
  149. then
  150. echo "dir $dir already exist!" 1>&2
  151. else
  152. mkdir -p "$dir" && {
  153. cd "$dir" &&
  154. git init --bare --shared=all
  155. }
  156. fi
  157. cd ${cdir}
  158. }
  159. bak(){
  160. for file in "$@"
  161. do
  162. mv -v ${file} ${file}.bak
  163. done
  164. }
  165. di(){
  166. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  167. then
  168. local diffcmd=colordiff
  169. else
  170. local diffcmd=diff
  171. fi
  172. ${diffcmd} -u "$@" | ${PAGER}
  173. }
  174. throw-away(){
  175. mkdir -p ~/.backup/tb
  176. for file in "$@"
  177. do
  178. mv $file ~/.backup/tb
  179. done
  180. }
  181. mkcd(){
  182. mkdir -p $1
  183. cd $1
  184. }
  185. catclip(){
  186. if iswindows
  187. then
  188. cat /dev/clipboard | tr -d \\r
  189. else
  190. xclip -o -selection "clipboard"
  191. fi
  192. }
  193. setclip(){
  194. if iswindows
  195. then
  196. if test $# -eq 0
  197. then
  198. sed -e 's/$/\r/' | tee /dev/clipboard
  199. else
  200. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  201. fi
  202. else
  203. if test $# -eq 0
  204. then
  205. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  206. else
  207. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  208. fi
  209. fi
  210. }
  211. o(){
  212. if [ $# -eq 0 ]
  213. then
  214. local f=.
  215. else
  216. local f="$1"
  217. fi
  218. if iswindows
  219. then
  220. cmd.exe //c start "" "$f"
  221. elif isdarwin
  222. then
  223. open "$f"
  224. elif type pcmanfm >/dev/null 2>&1
  225. then
  226. pcmanfm "$f"
  227. else
  228. xdg-open "$f"
  229. fi
  230. }
  231. convmv-sjis2utf8-test(){
  232. convmv -r -f sjis -t utf8 *
  233. }
  234. convmv-sjis2utf8-notest(){
  235. convmv -r -f sjis -t utf8 * --notest
  236. }
  237. _mygitconfig(){
  238. git config --global user.name '10sr'
  239. git config --global user.email '8slashes+git@gmail.com'
  240. git config --global core.autocrlf false
  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=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  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. # http://www.frexx.de/xterm-256-notes/data/colortable16.sh
  317. _install_script(){
  318. mkdir -p $HOMO/bin/
  319. for f in "$@"
  320. do
  321. bn=$(basename "$f")
  322. type ${bn} >/dev/null 2>&1 || wget "$f" -P "$HOME/bin/"
  323. chmod u+x "$HOME/bin/${bn}"
  324. done
  325. }
  326. winln(){
  327. # for windose make link (actually junction)
  328. if test $# -eq 0
  329. then
  330. {
  331. echo "usage: winln TARGET LINK_NAME"
  332. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  333. echo "About other features run 'junction'."
  334. } 1>&2
  335. return 1
  336. else
  337. junction "$2" "$1"
  338. fi
  339. }
  340. battery-status(){
  341. local dir=/sys/class/power_supply/BAT0
  342. if test -d $dir
  343. then
  344. local st=$(cat $dir/status)
  345. local full=$(cat $dir/charge_full)
  346. local now=$(cat $dir/charge_now)
  347. local rate=$(expr $now \* 100 / $full)
  348. printf "$1" "${st}:${rate}%"
  349. fi
  350. }
  351. alias bat='battery-status %s\\n'
  352. battery-status2(){
  353. local dir=/sys/class/power_supply/BAT0
  354. . $dir/uevent
  355. local rate=$(expr $POWER_SUPPLY_CHARGE_NOW \* 100 / $POWER_SUPPLY_CHARGE_FULL)
  356. echo ${POWER_SUPPLY_STATUS}:${rate}%
  357. }
  358. ip-address(){
  359. local ip=$(LANG=C ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}')
  360. test -n "$ip" && printf $1 $ip
  361. }
  362. __my_prompt_function(){ # used by PS1
  363. local lastreturn=$?
  364. if test "${TERM}" == dumb
  365. then
  366. local c1=
  367. local c2=
  368. local c3=
  369. local cdef=
  370. else
  371. local c1="\e[33m"
  372. local c2="\e[36m"
  373. local c3="\e[37m"
  374. local cdef="\e[0m"
  375. fi
  376. if iswindows
  377. then
  378. local pwd=$PWD
  379. local oldpwd=$OLDPWD
  380. git branch >/dev/null 2>&1 && local git="[GIT]"
  381. local date=$(/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%')
  382. else
  383. local pwd=$(echo "${PWD}/" | sed -e "s#${HOME}#~#")
  384. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s#${HOME}#~#")
  385. local jobnum=$(jobs | wc -l)
  386. local git=$(__try_exec __git_ps1 [GIT:%s])
  387. local date=$(LANG=C __try_exec date +"%a, %d %b %Y %T %z")
  388. fi
  389. # local svn=$(type svn >/dev/null 2>&1 && __try_exec __my_svn_ps1 [SVN:%s])
  390. if test -z "$DISPLAY"
  391. then
  392. local ip=$(ip-address [Addr:%s])
  393. test -f /tmp/batterystatus && local battery="[Battery:$(sed -e 's`%`%%`g' /tmp/batterystatus)]"
  394. battery-status %s >/tmp/batterystatus &
  395. fi
  396. local tty=$(__try_exec tty | sed -e 's:/dev/::')
  397. # local battery=$(battery-state [%s] | sed -e 's`%`%%`g') # very slow
  398. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}${battery}${ip}\n"
  399. printf "${c2}${USER}@${HOSTNAME}${cdef} ${tty} ${date} ${BASH} ${BASH_VERSION}\n"
  400. printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} "
  401. }
  402. # from https://wiki.archlinux.org/index.php/X_resources
  403. invader(){
  404. # ANSI color scheme script featuring Space Invaders
  405. #
  406. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  407. # Modified by lolilolicon
  408. #
  409. f=3 b=4
  410. for j in f b; do
  411. for i in {0..7}; do
  412. printf -v $j$i %b "\e[${!j}${i}m"
  413. done
  414. done
  415. bld=$'\e[1m'
  416. rst=$'\e[0m'
  417. cat << EOF
  418. $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  419. $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  420. $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
  421. $f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst
  422. $bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  423. $bld$f1█▄█▀███▀█▄█ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4█▄█▀███▀█▄█ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  424. $bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst
  425. $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
  426. $f7▌$rst
  427. $f7▌$rst
  428. $f7 ▄█▄ $rst
  429. $f7▄█████████▄$rst
  430. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  431. EOF
  432. }