Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

bashrc 14 KiB

13 lat temu
13 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
13 lat temu
13 lat temu
13 lat temu
12 lat temu
12 lat temu
12 lat temu
13 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
13 lat temu
12 lat temu
12 lat temu
12 lat temu
13 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
13 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
13 lat temu
12 lat temu
13 lat temu
12 lat temu
12 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
12 lat temu
13 lat temu
13 lat temu
12 lat temu
12 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
12 lat temu
13 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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 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 sudo="sudo " # use aliases through sudo
  83. alias e3=e3em
  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. o(){
  216. if [ $# -eq 0 ]
  217. then
  218. local f=.
  219. else
  220. local f="$1"
  221. fi
  222. if iswindows
  223. then
  224. cmd.exe //c start "" "$f"
  225. elif isdarwin
  226. then
  227. open "$f"
  228. elif type pcmanfm >/dev/null 2>&1
  229. then
  230. LC_MESSAGES= pcmanfm "$f"
  231. else
  232. LC_MESSAGES= xdg-open "$f"
  233. fi
  234. }
  235. convmv-sjis2utf8-test(){
  236. convmv -r -f sjis -t utf8 *
  237. }
  238. convmv-sjis2utf8-notest(){
  239. convmv -r -f sjis -t utf8 * --notest
  240. }
  241. _mygitconfig(){
  242. git config --global user.name '10sr'
  243. git config --global user.email '8slashes+git@gmail.com'
  244. git config --global core.autocrlf false
  245. git config --global color.ui auto
  246. git config --global status.relativePaths false
  247. git config --global status.showUntrackedFiles normal
  248. git config --global alias.graph "log --graph --date-order -C -M --pretty=tformat:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  249. git config --global alias.st "status -s"
  250. git config --global alias.b "branch"
  251. git config --global alias.ci "commit --verbose"
  252. git config --global alias.co "checkout"
  253. git config --global alias.cim "commit --verbose -m"
  254. git config --global alias.di "diff --color"
  255. git config --global alias.me "merge --no-ff --stat -v"
  256. git config --global alias.ls "ls-files -v --full-name"
  257. git config --global alias.sl "!sl"
  258. # git config --global alias.my-ls "ls-files | xargs ls"
  259. # git config --global alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  260. git config --global alias.addi "add -i"
  261. if iswindows; then
  262. git config --global core.fileMode false
  263. fi
  264. }
  265. __my_parse_svn_branch() {
  266. local LANG=C
  267. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  268. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  269. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  270. }
  271. __my_svn_ps1(){
  272. if svn status >/dev/null 2>&1
  273. then
  274. local svn_branch=$(__my_parse_svn_branch)
  275. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  276. fi
  277. }
  278. #Change ANSI Colors
  279. _chengecolors(){
  280. echo -e \
  281. "\e]P0000000" \
  282. "\e]P1cd0000" \
  283. "\e]P200cd00" \
  284. "\e]P3cdcd00" \
  285. "\e]P41e90ff" \
  286. "\e]P5cd00cd" \
  287. "\e]P600cdcd" \
  288. "\e]P7353535" \
  289. "\e]P8666666" \
  290. "\e]P9ff9999" \
  291. "\e]Pa99ff99" \
  292. "\e]Pbffff99" \
  293. "\e]Pc9999ff" \
  294. "\e]Pdff99ff" \
  295. "\e]Pe99ffff" \
  296. "\e]Pfffffff"
  297. }
  298. # printf "\e]P7353535" \
  299. _colors(){
  300. echo -e \
  301. "\e[30mBlack" \
  302. "\e[31mRed" \
  303. "\e[32mGreen" \
  304. "\e[33mYellow" \
  305. "\e[34mBlue" \
  306. "\e[35mMagenta" \
  307. "\e[36mCyan" \
  308. "\e[37mWhite"
  309. echo -e \
  310. "\e[30;1mBright Black" \
  311. "\e[31;1mBright Red" \
  312. "\e[32;1mBright Green" \
  313. "\e[33;1mBright Yellow" \
  314. "\e[34;1mBright Blue" \
  315. "\e[35;1mBright Magenta" \
  316. "\e[36;1mBright Cyan" \
  317. "\e[37;1mBright White\n" \
  318. "\e[0m"
  319. }
  320. # http://www.frexx.de/xterm-256-notes/data/colortable16.sh
  321. _install_script(){
  322. mkdir -p $HOMO/bin/
  323. for f in "$@"
  324. do
  325. bn=$(basename "$f")
  326. type ${bn} >/dev/null 2>&1 || wget "$f" -P "$HOME/bin/"
  327. chmod u+x "$HOME/bin/${bn}"
  328. done
  329. }
  330. winln(){
  331. # for windose make link (actually junction)
  332. if test $# -eq 0
  333. then
  334. {
  335. echo "usage: winln TARGET LINK_NAME"
  336. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  337. echo "About other features run 'junction'."
  338. } 1>&2
  339. return 1
  340. else
  341. junction "$2" "$1"
  342. fi
  343. }
  344. battery-status(){
  345. local dir=/sys/class/power_supply/BAT0
  346. if test -d $dir
  347. then
  348. local st=$(cat $dir/status)
  349. local full=$(cat $dir/charge_full)
  350. local now=$(cat $dir/charge_now)
  351. local rate=$(expr $now \* 100 / $full)
  352. printf "$1" "${st}:${rate}%"
  353. fi
  354. }
  355. alias bat='battery-status %s\\n'
  356. battery-status2(){
  357. local dir=/sys/class/power_supply/BAT0
  358. . $dir/uevent
  359. local rate=$(expr $POWER_SUPPLY_CHARGE_NOW \* 100 / $POWER_SUPPLY_CHARGE_FULL)
  360. echo ${POWER_SUPPLY_STATUS}:${rate}%
  361. }
  362. ip-address(){
  363. local ip=$(LANG=C ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}')
  364. test -n "$ip" && printf $1 $ip
  365. }
  366. __my_prompt_function(){ # used by PS1
  367. # remove __try_exec from function
  368. local lastreturn=$?
  369. if test "${TERM}" == dumb
  370. then
  371. local c1=
  372. local c2=
  373. local c3=
  374. local cdef=
  375. else
  376. local c1="\e[33m"
  377. local c2="\e[36m"
  378. local c3="\e[37m"
  379. local cdef="\e[0m"
  380. fi
  381. if iswindows
  382. then
  383. local pwd=$PWD
  384. local oldpwd=$OLDPWD
  385. git branch >/dev/null 2>&1 && local git="[GIT]"
  386. local date=$(/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%')
  387. else
  388. local pwd=$(echo "${PWD}/" | sed -e "s#${HOME}#~#")
  389. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s#${HOME}#~#")
  390. local jobnum=$(jobs | wc -l)
  391. local git=$(__try_exec __git_ps1 [GIT:%s])
  392. local date=$(LANG=C __try_exec date +"%a, %d %b %Y %T %z")
  393. fi
  394. # local svn=$(type svn >/dev/null 2>&1 && __try_exec __my_svn_ps1 [SVN:%s])
  395. if test -z "$DISPLAY"
  396. then
  397. local ip=$(ip-address [Addr:%s])
  398. local bst="/tmp/${USER}-tmp/batterystatus"
  399. test -f $bst && local battery="[Battery:$(sed -e 's`%`%%`g' $bst)]"
  400. battery-status %s >$bst &
  401. fi
  402. local tty=$(__try_exec tty | sed -e 's:/dev/::')
  403. # local battery=$(battery-state [%s] | sed -e 's`%`%%`g') # very slow
  404. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}${battery}${ip}\n"
  405. printf "${c2}${USER}@${HOSTNAME}${cdef} ${tty} ${date} ${BASH} ${BASH_VERSION}\n"
  406. printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} "
  407. }
  408. # from https://wiki.archlinux.org/index.php/X_resources
  409. invader(){
  410. # ANSI color scheme script featuring Space Invaders
  411. #
  412. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  413. # Modified by lolilolicon
  414. #
  415. f=3 b=4
  416. for j in f b; do
  417. for i in {0..7}; do
  418. printf -v $j$i %b "\e[${!j}${i}m"
  419. done
  420. done
  421. bld=$'\e[1m'
  422. rst=$'\e[0m'
  423. cat << EOF
  424. $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  425. $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  426. $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
  427. $f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst
  428. $bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  429. $bld$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. $f7▌$rst
  433. $f7▌$rst
  434. $f7 ▄█▄ $rst
  435. $f7▄█████████▄$rst
  436. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  437. EOF
  438. }