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.

pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #!/bin/bash
  2. # If not running interactively, don't do anything
  3. [[ $- != *i* ]] && return
  4. ##########################################
  5. null(){
  6. "$@" >/dev/null 2>&1
  7. }
  8. __try_exec(){
  9. type $1 >/dev/null 2>&1 && "$@"
  10. }
  11. ##########################
  12. # system type
  13. alias ismsys=false
  14. alias iscygwin=false
  15. alias iswindows=false
  16. alias isdarwin=false
  17. alias islinux=false
  18. alias with_coreutils=false # for mac
  19. case `uname` in
  20. (MINGW*) alias ismsys=true ;;
  21. (CYGWIN*) alias iscygwin=true ;;
  22. (Darwin*) alias isdarwin=true ;;
  23. (Linux*) alias islinux=true ;;
  24. esac
  25. null ls --version && alias with_coreutils=true
  26. ( ismsys || iscygwin ) && alias iswindows=true
  27. #################################
  28. if false iswindows
  29. then
  30. export PAGER='tr -d \\r | less'
  31. else
  32. export PAGER="less"
  33. fi
  34. export LESS="-iRMXF"
  35. if null type vim
  36. then
  37. export EDITOR=vim
  38. else
  39. export EDITOR=vi
  40. fi
  41. export LANG=ja_JP.UTF-8
  42. export LC_MESSAGES=C
  43. # export CDPATH=".:~"
  44. export VISUAL="$EDITOR"
  45. export GIT_PAGER="$PAGER"
  46. export GIT_EDITOR="$EDITOR"
  47. echo "$TERM" | grep '^screen' >/dev/null 2>&1 || export TERM_ORIG=$TERM
  48. test "$TERM" = screen && test "$TERM_ORIG" = xterm-256color && TERM=screen-256color
  49. test -z "$TMP" && export TMP=/tmp/${USER}-tmp
  50. mkdir -p "$TMP"
  51. ! iswindows && null type stty && {
  52. stty stop undef # unbind C-s to stop displaying output
  53. # stty erase '^h'
  54. }
  55. if iswindows; then
  56. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  57. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  58. export USER=$USERNAME
  59. fi
  60. _tmux_prefs(){
  61. null type tmux || return 1
  62. tmux set -g mode-keys vi
  63. }
  64. #######################
  65. iswindows && alias tty="echo cmd.exe"
  66. type fortune >/dev/null 2>&1 && {
  67. fortune
  68. echo
  69. fortune -o
  70. echo
  71. }
  72. uname -a
  73. echo TERM $TERM $(tput colors) colors connected to $(tty), running $BASH $BASH_VERSION
  74. echo
  75. ###################################
  76. # some aliases and functions
  77. ( ! with_coreutils && isdarwin ) || test "$TERM" == dumb || _coloroption=" --color=auto"
  78. ( ! with_coreutils && isdarwin ) || iswindows || _timeoption=" --time-style=long-iso"
  79. ( ! with_coreutils && isdarwin ) || _hideoption=" --hide=[A-Z]*" # do not use
  80. _timeformat_iso="%Y-%m-%dT%H:%M:%S%z"
  81. _timeformat_rfc2822="%a, %d %b %Y %T %z"
  82. alias ls="ls -hCF${_coloroption}${_timeoption}"
  83. # export GREP_OPTIONS=""
  84. alias gr="grep -n${_coloroption}"
  85. iswindows && alias grep="grep -n"
  86. # alias ll="ls -l"
  87. # alias la="ls -A"
  88. # alias lla="ls -Al"
  89. # alias less=""
  90. alias em="emacs -nw"
  91. null type vim && alias vi=vim
  92. alias pstree="LANG=C pstree"
  93. alias cp="cp -v"
  94. alias mv="mv -v"
  95. alias rm="rm -v"
  96. alias psaux="ps auxww"
  97. alias q=exit
  98. alias e3=e3em
  99. #alias dirs="dirs -v -l | \grep -v \$(printf '%s$' \$PWD)"
  100. alias po=popd
  101. alias pu=pushd
  102. alias sudo="sudo " # use aliases through sudo
  103. alias halt="sudo halt"
  104. alias reboot="sudo reboot"
  105. alias suspend="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  106. /org/freedesktop/UPower org.freedesktop.UPower.Suspend"
  107. alias hibernate="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  108. /org/freedesktop/UPower org.freedesktop.UPower.Hibernate"
  109. alias rand="echo \$RANDOM"
  110. alias xunp="file-roller -h"
  111. alias pc="sudo \paco -D"
  112. alias pycalc="python -i -c 'from math import *' "
  113. alias py3=python3
  114. alias py2=python2
  115. alias _reloadrc="test -f ~/.bashrc && source ~/.bashrc"
  116. # alias mytime="date +%Y%m%d-%H%M%S"
  117. alias sh="ENV=$HOME/.shrc PS1=\$\ PROMPT_COMMAND="" sh"
  118. # type trash >/dev/null 2>&1 && alias rm=trash
  119. alias mpg123="mpg123 -C -v --title"
  120. export PLAYER="mpg123 -C -v --title"
  121. null type screen && alias screen="screen -e^z^z"
  122. alias zcd="cd \`zenity --file-selection --directory\`"
  123. null type gtags && alias gtags="gtags --verbose"
  124. null type htags && alias htags="htags --xhtml --symbol --line-number \
  125. --frame --alphabet --verbose"
  126. alias pad=notepad
  127. null type gedit && alias pad=gedit
  128. null type leafpad && alias pad=leafpad
  129. isdarwin && alias pad="open -e"
  130. alias wic=wicd-curses
  131. alias wil="wicd-cli -y -l | head"
  132. #alias wicn="wicd-cli -y -c -n"
  133. wicn(){
  134. if test $# -eq 0
  135. then
  136. local num
  137. wicd-cli -y -l | head
  138. echo -n "input num: "
  139. read num
  140. test -n "$num" && wicd-cli -y -c -n $num
  141. else
  142. wicd-cli -y -c -n $1
  143. fi
  144. }
  145. alias aptin="apt-get install"
  146. alias aptsearch="apt-cache search"
  147. alias aptshow="apt-cache show"
  148. for f in /usr/share/vim/vimcurrent/macros/less.sh \
  149. /usr/share/vim/vim73/macros/less.sh \
  150. /usr/share/vim/vim72/macros/less.sh
  151. do
  152. test -f $f && alias vl=$f && break
  153. done
  154. alias yt=yaourt
  155. null type pacman-color && {
  156. alias pacman=pacman-color
  157. export pacman_program=pacman-color # used by pacmatic
  158. export PACMAN=pacman-color # used by yaourt
  159. }
  160. null type pacmatic && {
  161. alias pacman="pacmatic"
  162. export PACMAN="pacmatic"
  163. }
  164. null type apt-get && \
  165. alias aupgrade="sudo apt-get autoremove --yes && sudo apt-get update --yes && sudo apt-get upgrade --yes"
  166. null type port && \
  167. alias port="port -v"
  168. alias pupgrade="sudo port -v selfupdate && { sudo port -v upgrade outdated; }"
  169. if iscygwin; then
  170. null type windate || alias windate="/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%'"
  171. alias cygsu="cygstart /cygwinsetup.exe"
  172. alias emacs="CYGWIN=tty emacs -nw"
  173. alias ls="ls -CFG $(iswindows || test "$TERM" == dumb || echo --color=auto)"
  174. fi
  175. alias g=git
  176. if null type _git
  177. then
  178. # enable programmable completion for g
  179. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  180. || complete -o default -o nospace -F _git g
  181. fi
  182. alias setup.py="sudo python3 setup.py install --record files.txt"
  183. scr(){
  184. _tformat="%Y-%m-%dT%H:%M:%S%z"
  185. _file=`date +${_tformat}`.script
  186. SCRIPT=${_file} script ${_file} "$@"
  187. }
  188. netwait(){
  189. while ! ping -c 1 -t 1 example.com
  190. do
  191. true
  192. done
  193. echo network works.
  194. }
  195. cd(){
  196. if test $# -eq 0
  197. then
  198. pushd ~/ >/dev/null
  199. elif test $1 = -
  200. then
  201. local pwd="$PWD"
  202. command cd $OLDPWD
  203. pushd -n "$pwd" >/dev/null # stack last dir
  204. elif ! test -d "$1"
  205. then
  206. echo `basename ${SHELL}`: cd: "$1": No such file or directory 1>&2
  207. return 1
  208. else
  209. pushd "$1" >/dev/null
  210. fi
  211. __dirs_rm_dup "$PWD"
  212. echo "$PWD"
  213. }
  214. __dirs_rm_dup(){
  215. for d in "$@"
  216. do
  217. local next="$(__realpath --strip "$d")"
  218. for l in $(\dirs -v -l | cut -d $'\n' -f 2- | \grep -x " *[0-9]\+ \+${next}" | \grep -o "^ *[0-9]\+ " | tac)
  219. do
  220. popd +$l -n >/dev/null
  221. done
  222. done
  223. }
  224. __realpath(){
  225. if type realpath >/dev/null 2>&1
  226. then
  227. command realpath "$@"
  228. else
  229. while ! test -d $1
  230. do
  231. shift
  232. done
  233. local d="$OLDPWD"
  234. command cd "$1"
  235. echo "$PWD"
  236. command cd "$d"
  237. fi
  238. }
  239. dh(){
  240. if test $# -eq 0
  241. then
  242. dirs -v -l
  243. else
  244. local dir="$(dirs -v -l | \grep "^ *$1 \+" | sed "s/^ *[0-9]* *//g")"
  245. cd "$dir"
  246. fi
  247. }
  248. input(){
  249. local foo
  250. stty -echo
  251. read foo
  252. stty echo
  253. echo $foo
  254. }
  255. tmux(){
  256. if test $# -eq 0
  257. then
  258. (cd ~; command tmux start;)
  259. if command tmux has -t main
  260. then
  261. command tmux attach -t main
  262. else
  263. command tmux new -s main
  264. fi
  265. else
  266. command tmux "$@"
  267. fi
  268. }
  269. mcrypt-stream(){
  270. test $# -eq 2 || return 1
  271. case $1 in
  272. en)
  273. mcrypt --key $2 | base64 ;;
  274. de)
  275. base64 -d | mcrypt -d --key $2 ;;
  276. esac
  277. }
  278. gpg-stream(){
  279. test $# -eq 2 || return 1
  280. case $1 in
  281. en)
  282. gpg --passphrase $2 -c --batch |base64 ;;
  283. de)
  284. base64 -d|gpg --passphrase $2 -d --batch ;;
  285. esac
  286. }
  287. alias enst="gpg-stream en"
  288. alias dest="gpg-stream de"
  289. showinfo(){
  290. echo "Japanese letters are 表示可能"
  291. __try_exec diskinfo
  292. ! isdarwin && test -n "${DISPLAY}" && {
  293. __try_exec xrandr | \grep --color=never ^Screen
  294. }
  295. iswindows || __try_exec finger $USER
  296. LANG=C __try_exec id
  297. __try_exec xset q
  298. }
  299. x(){
  300. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  301. #mkdir -p ~/.my/log
  302. # nohup startx >~/.my/log/xorg.log 2>&1 &
  303. # exit
  304. exec startx
  305. else
  306. echo "X cant be started! Maybe another X is already running or something." 1>&2
  307. fi
  308. }
  309. bak(){
  310. for file in "$@"
  311. do
  312. cp -v ${file} ${file}.bak
  313. done
  314. }
  315. di(){
  316. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  317. then
  318. local diffcmd=colordiff
  319. else
  320. local diffcmd=diff
  321. fi
  322. ${diffcmd} -u "$@" | ${PAGER}
  323. }
  324. tb(){
  325. local tb="$HOME/.my/tb"
  326. mkdir -p "$tb"
  327. for file in "$@"
  328. do
  329. mv -t "$tb" "$file"
  330. done
  331. }
  332. mkcd(){
  333. mkdir -p $1
  334. cd $1
  335. }
  336. if test -n "$TMUX" && null type reattach-to-user-namespace
  337. then
  338. alias pbpaste="reattach-to-user-namespace pbpaste"
  339. alias pbcopy="reattach-to-user-namespace pbcopy"
  340. fi
  341. catclip(){
  342. if iswindows
  343. then
  344. cat /dev/clipboard | tr -d \\r
  345. elif isdarwin
  346. then
  347. pbpaste
  348. else
  349. xclip -o -selection "clipboard"
  350. fi
  351. }
  352. setclip(){
  353. if iswindows
  354. then
  355. if test $# -eq 0
  356. then
  357. sed -e 's/$/\r/' | tee /dev/clipboard
  358. else
  359. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  360. fi
  361. elif isdarwin
  362. then
  363. if test $# -eq 0
  364. then
  365. pbcopy
  366. else
  367. cat "$@" | pbcopy
  368. fi
  369. else
  370. if test $# -eq 0
  371. then
  372. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  373. else
  374. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  375. fi
  376. fi
  377. }
  378. open_file(){
  379. if iswindows
  380. then
  381. cmd.exe //c start "" "$@"
  382. elif isdarwin
  383. then
  384. touch "$@"
  385. open "$@"
  386. elif islinux
  387. then
  388. touch "$@"
  389. if null type pcmanfm; then
  390. LC_MESSAGES= pcmanfm "$@"
  391. else
  392. LC_MESSAGES= xdg-open "$@" &
  393. fi
  394. else
  395. cat "$@"
  396. fi
  397. }
  398. o(){
  399. if test $# -eq 0
  400. then
  401. open_file .
  402. else
  403. for f in "$@"
  404. do
  405. open_file "$(realpath "$f")"
  406. done
  407. fi
  408. }
  409. convmv-sjis2utf8-test(){
  410. convmv -r -f sjis -t utf8 *
  411. }
  412. convmv-sjis2utf8-notest(){
  413. convmv -r -f sjis -t utf8 * --notest
  414. }
  415. __my_moc_state(){
  416. type mocp >/dev/null 2>&1 || return
  417. test "`mocp -Q %state 2>/dev/null`" == PLAY || return
  418. printf "$1" "`mocp -Q %title 2>/dev/null`"
  419. }
  420. __my_parse_svn_branch() {
  421. local LANG=C
  422. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  423. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  424. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  425. }
  426. __my_svn_ps1(){
  427. if svn status >/dev/null 2>&1
  428. then
  429. local svn_branch=$(__my_parse_svn_branch)
  430. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  431. fi
  432. }
  433. #Change ANSI Colors
  434. _chengecolors(){
  435. echo -e \
  436. "\e]P0000000" \
  437. "\e]P1cd0000" \
  438. "\e]P200cd00" \
  439. "\e]P3cdcd00" \
  440. "\e]P41e90ff" \
  441. "\e]P5cd00cd" \
  442. "\e]P600cdcd" \
  443. "\e]P7353535" \
  444. "\e]P8666666" \
  445. "\e]P9ff9999" \
  446. "\e]Pa99ff99" \
  447. "\e]Pbffff99" \
  448. "\e]Pc9999ff" \
  449. "\e]Pdff99ff" \
  450. "\e]Pe99ffff" \
  451. "\e]Pfffffff"
  452. }
  453. # printf "\e]P7353535" \
  454. _colors(){
  455. echo -e \
  456. "\e[30mBlack" \
  457. "\e[31mRed" \
  458. "\e[32mGreen" \
  459. "\e[33mYellow" \
  460. "\e[34mBlue" \
  461. "\e[35mMagenta" \
  462. "\e[36mCyan" \
  463. "\e[37mWhite"
  464. echo -e \
  465. "\e[30;1mBright Black" \
  466. "\e[31;1mBright Red" \
  467. "\e[32;1mBright Green" \
  468. "\e[33;1mBright Yellow" \
  469. "\e[34;1mBright Blue" \
  470. "\e[35;1mBright Magenta" \
  471. "\e[36;1mBright Cyan" \
  472. "\e[37;1mBright White\n" \
  473. "\e[0m"
  474. }
  475. winln(){
  476. # for windose make link (actually junction)
  477. if test $# -eq 0
  478. then
  479. {
  480. echo "usage: winln TARGET LINK_NAME"
  481. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  482. echo "About other features run 'junction'."
  483. } 1>&2
  484. return 1
  485. else
  486. junction "$2" "$1"
  487. fi
  488. }
  489. __my_battery_status(){
  490. local dir=/sys/class/power_supply/BAT0
  491. if test -d $dir && test -r $dir/status && test -r $dir/charge_full && test -r $dir/charge_now
  492. then
  493. local st=$(cat $dir/status)
  494. local full=$(cat $dir/charge_full)
  495. local now=$(cat $dir/charge_now)
  496. local rate=$(expr $now \* 100 / $full)
  497. printf "$1" "${st}:${rate}%"
  498. fi
  499. }
  500. alias bat='__my_battery_status %s\\n'
  501. ip-address(){
  502. type ip >/dev/null 2>&1 || return 1
  503. local ip=$(LANG=C ip addr show scope global | \grep --color=never --only-matching 'inet [^ ]*' | cut -d " " -f 2)
  504. test -n "$ip" && printf $1 $ip
  505. }
  506. __my_ps1_script(){
  507. local last=$?
  508. test -n "$SCRIPT" && echo "SCR "
  509. return $last
  510. }
  511. __my_ps1_scale(){
  512. local last=$?
  513. echo "[LC:${LINES}x${COLUMNS}]"
  514. return $last
  515. }
  516. __my_ps1_tmux(){
  517. local last=$?
  518. null type tmux || return $last
  519. local tmuxc="$(tmux display -p '#S:#I:#W.#P' 2>/dev/null)"
  520. test -n "$TMUX" && echo "[TMUX:$tmuxc]"
  521. return $last
  522. }
  523. __my_ps1_moc(){
  524. local last=$?
  525. __my_moc_state "[MOC:%s]"
  526. return $last
  527. }
  528. for f in /usr/share/git/git-prompt.sh \
  529. /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh
  530. do
  531. test -r $f && . $f && break
  532. done
  533. GIT_PS1_SHOWDIRTYSTATE=t
  534. GIT_PS1_SHOWUPSTREAM=t
  535. __my_ps1_git(){
  536. local last=$?
  537. null type __git_ps1 || return $last
  538. null __gitdir || return $last
  539. __git_ps1 "[GIT:$(__try_exec git config --get user.name):%s]"
  540. return $last
  541. }
  542. __my_ps1_ipaddr(){
  543. local last=$?
  544. ! iswindows && ip-address [Addr:%s]
  545. return $last
  546. }
  547. __my_ps1_bttry(){
  548. local last=$?
  549. local bst="${TMP}/batterystatus"
  550. if test -z "$DISPLAY" && ! iswindows
  551. then
  552. test -f $bst && local bstr="$(cat $bst)"
  553. test -n "$bstr" && echo "[Battery:$bstr]"
  554. __my_battery_status %s >$bst &
  555. fi
  556. return $last
  557. }
  558. __my_ps1_dirs(){
  559. dirs | wc -l
  560. }
  561. __my_ps1_jobs(){
  562. jobs | wc -l
  563. }
  564. if test "$TERM" != dumb
  565. then
  566. __my_c1="\[\e[1;31m\]" # color for PWD
  567. __my_c2="\[\e[0;36m\]" # color for user
  568. __my_c3="\[\e[1;30m\]" # color for OLDPWD
  569. if test "`hostname`" = arch-aspireone; then __my_c4="\[\e[1;34m\]"
  570. elif test "`hostname`" = darwin-mba.local; then __my_c4="\[\e[1;33m\]"
  571. elif test "`hostname`" = newkiwi; then __my_c4="\[\e[1;35m\]"
  572. else __my_c4="\[\e[1;32m\]" # color for ::
  573. fi
  574. __my_cdef="\[\e[0m\]"
  575. fi
  576. _PS1="\
  577. ${__my_c4}:: ${__my_cdef}[${__my_c2}\u@\H${__my_cdef}:${__my_c1}\w/${__my_cdef}]\$(__my_ps1_scale)\$(__my_ps1_tmux)\$(__my_ps1_git)\$(__my_ps1_bttry)\$(__my_ps1_ipaddr)\$(__my_ps1_moc)\n\
  578. ${__my_c4}:: ${__my_cdef}l${SHLVL}n\#j\js\$? \D{%T} $(__my_ps1_script)\$ "
  579. PS1=$_PS1
  580. __my_set_title(){
  581. title="$(echo $@)"
  582. case $TERM in
  583. (rxvt*|xterm*|aterm|screen*)
  584. test -t 1 &&
  585. test -n "$DISPLAY" &&
  586. test -z "$EMACS" &&
  587. echo -n -e "\033]0;${title}\007"
  588. ;;
  589. esac
  590. }
  591. PROMPT_COMMAND="__my_set_title \${USER}@\${HOSTNAME}\ \${PWD}"
  592. # copied from https://wiki.archlinux.org/index.php/X_resources
  593. invader(){
  594. # ANSI color scheme script featuring Space Invaders
  595. #
  596. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  597. # Modified by lolilolicon
  598. #
  599. f=3 b=4
  600. for j in f b; do
  601. for i in {0..7}; do
  602. printf -v $j$i %b "\e[${!j}${i}m"
  603. done
  604. done
  605. bld=$'\e[1m'
  606. rst=$'\e[0m'
  607. cat << EOF
  608. $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  609. $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  610. $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
  611. $f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst
  612. $bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  613. $bld$f1█▄█▀███▀█▄█ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4█▄█▀███▀█▄█ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  614. $bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst
  615. $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
  616. $f7▌$rst
  617. $f7▌$rst
  618. $f7 ▄█▄ $rst
  619. $f7▄█████████▄$rst
  620. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  621. EOF
  622. }
  623. #/etc/lsb-release