25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

505 satır
14 KiB

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