├── bin ├── sudo ├── pbcopy ├── pbpaste ├── vn ├── vcvarsall └── rename ├── .gitignore ├── etc └── hosts ├── vim ├── .vim │ ├── snippets │ │ ├── snippet.snippets │ │ ├── _.snippets │ │ ├── cpp.snippets │ │ ├── sh.snippets │ │ ├── vim.snippets │ │ ├── markdown.snippets │ │ ├── mako.snippets │ │ ├── zsh.snippets │ │ ├── autoit.snippets │ │ ├── java.snippets │ │ ├── javascript.snippets │ │ ├── tcl.snippets │ │ ├── perl.snippets │ │ ├── python.snippets │ │ ├── tex.snippets │ │ ├── c.snippets │ │ ├── objc.snippets │ │ ├── php.snippets │ │ ├── html.snippets │ │ ├── objcpp.snippets │ │ └── ruby.snippets │ ├── .VimballRecord │ └── autoload │ │ └── pathogen.vim └── .vimrc ├── vnc └── xstartup ├── script ├── create_windows_symlinks ├── update_hosts ├── bash_utils ├── solarize ├── update_node └── bootstrap ├── misc └── .minttyrc ├── git └── .gitconfig ├── bash ├── .tools_aliases └── .bashrc └── .gitmodules /bin/sudo: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | "$@" 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | vim/.vim/.netrwhist 3 | -------------------------------------------------------------------------------- /bin/pbcopy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cat > /dev/clipboard 4 | -------------------------------------------------------------------------------- /bin/pbpaste: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cat /dev/clipboard 4 | -------------------------------------------------------------------------------- /etc/hosts: -------------------------------------------------------------------------------- 1 | 192.168.1.16 pi 2 | 192.168.1.22 push 3 | 192.168.1.17 4tb 4 | 192.168.1.42 m1 5 | 192.168.1.43 m3 6 | 192.168.1.24 kindle 7 | 192.168.1.91 air 8 | -------------------------------------------------------------------------------- /vim/.vim/snippets/snippet.snippets: -------------------------------------------------------------------------------- 1 | # snippets for making snippets :) 2 | snippet snip 3 | snippet ${1:trigger} 4 | ${2} 5 | snippet msnip 6 | snippet ${1:trigger} ${2:description} 7 | ${3} 8 | -------------------------------------------------------------------------------- /vim/.vim/snippets/_.snippets: -------------------------------------------------------------------------------- 1 | # Global snippets 2 | 3 | # (c) holds no legal value ;) 4 | snippet c) 5 | `&enc[:2] == "utf" ? "©" : "(c)"` Copyright `strftime("%Y")` ${1:`g:snips_author`}. All Rights Reserved.${2} 6 | snippet date 7 | `strftime("%Y-%m-%d")` 8 | -------------------------------------------------------------------------------- /vnc/xstartup: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Uncomment the following two lines for normal desktop: 4 | unset SESSION_MANAGER 5 | #exec /etc/X11/xinit/xinitrc 6 | gnome-session --session=gnome-classic & 7 | 8 | [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup 9 | [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources 10 | xsetroot -solid grey 11 | vncconfig -iconic & 12 | #x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" & 13 | #x-window-manager & 14 | -------------------------------------------------------------------------------- /script/create_windows_symlinks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Root of dotfiles 4 | SOURCE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.." 5 | 6 | TARGET=${1:-~} 7 | 8 | function link_if_not_exist { 9 | if [ ! -L "$TARGET/$1" ] && [ ! -e "$TARGET/$1" ]; then 10 | ln -s $2 "$TARGET/$1" 11 | fi 12 | } 13 | 14 | WIN_HOME="/cygdrive/${USERPROFILE/:/}" 15 | 16 | link_if_not_exist Desktop "$WIN_HOME/Desktop" 17 | link_if_not_exist Downloads "$WIN_HOME/Downloads" 18 | -------------------------------------------------------------------------------- /vim/.vim/.VimballRecord: -------------------------------------------------------------------------------- 1 | markdown-1.2.2.vba: call delete('/home/kitten/.vim/ftdetect/markdown.vim')|call delete('/home/kitten/.vim/snippets/markdown.snippets')|call delete('/home/kitten/.vim/syntax/markdown.vim') 2 | Align.vba: call delete('/home/kitten/.vim/plugin/AlignPlugin.vim')|call delete('/home/kitten/.vim/plugin/AlignMapsPlugin.vim')|call delete('/home/kitten/.vim/plugin/cecutil.vim')|call delete('/home/kitten/.vim/doc/Align.txt')|call delete('/home/kitten/.vim/autoload/Align.vim')|call delete('/home/kitten/.vim/autoload/AlignMaps.vim') 3 | -------------------------------------------------------------------------------- /vim/.vim/snippets/cpp.snippets: -------------------------------------------------------------------------------- 1 | # Namespace 2 | snippet ans 3 | namespace { 4 | 5 | ${0} 6 | 7 | } // namespace 8 | snippet fns 9 | namespace ${1:`Filename('', 'my')`} { 10 | ${0} 11 | } 12 | snippet ns 13 | namespace ${1:`Filename('', 'my')`} { 14 | 15 | ${0} 16 | 17 | } // namespace $1 18 | # Class 19 | snippet cl 20 | class ${1:`substitute(Filename('', 'name'), '\(\%(\<\l\+\)\%(_\)\@=\)\|_\(\l\)', '\u\1\2', 'g')`} ${0}{ 21 | public: 22 | $1(); 23 | ~$1() override; 24 | 25 | private: 26 | DISALLOW_COPY_AND_ASSIGN($1); 27 | }; 28 | -------------------------------------------------------------------------------- /vim/.vim/snippets/sh.snippets: -------------------------------------------------------------------------------- 1 | # #!/bin/bash 2 | snippet #! 3 | #!/bin/bash 4 | 5 | snippet if 6 | if [[ ${1:condition} ]]; then 7 | ${2:#statements} 8 | fi 9 | snippet elif 10 | elif [[ ${1:condition} ]]; then 11 | ${2:#statements} 12 | snippet for 13 | for (( ${2:i} = 0; $2 < ${1:count}; $2++ )); do 14 | ${3:#statements} 15 | done 16 | snippet wh 17 | while [[ ${1:condition} ]]; do 18 | ${2:#statements} 19 | done 20 | snippet until 21 | until [[ ${1:condition} ]]; do 22 | ${2:#statements} 23 | done 24 | snippet case 25 | case ${1:word} in 26 | ${2:pattern}) 27 | ${3};; 28 | esac 29 | -------------------------------------------------------------------------------- /misc/.minttyrc: -------------------------------------------------------------------------------- 1 | BoldAsFont=yes 2 | CursorType=block 3 | CopyOnSelect=no 4 | Columns=83 5 | Rows=34 6 | Scrollbar=none 7 | ForegroundColour=101,123,131 8 | BackgroundColour=253,246,227 9 | CursorColour=220,50,47 10 | Black=7,54,66 11 | BoldBlack=0,43,54 12 | Red=220,50,47 13 | BoldRed=203,75,22 14 | Green=133,153,0 15 | BoldGreen=88,110,117 16 | Yellow=181,137,0 17 | BoldYellow=101,123,131 18 | Blue=38,139,210 19 | BoldBlue=131,148,150 20 | Magenta=211,54,130 21 | BoldMagenta=108,113,196 22 | Cyan=42,161,152 23 | BoldCyan=147,161,161 24 | White=238,232,213 25 | BoldWhite=253,246,227 26 | Locale=C 27 | Charset=UTF-8 28 | -------------------------------------------------------------------------------- /vim/.vim/snippets/vim.snippets: -------------------------------------------------------------------------------- 1 | snippet header 2 | " File: ${1:`expand('%:t')`} 3 | " Author: ${2:`g:snips_author`} 4 | " Description: ${3} 5 | ${4:" Last Modified: `strftime("%B %d, %Y")`} 6 | snippet guard 7 | if exists('${1:did_`Filename()`}') || &cp${2: || version < 700} 8 | finish 9 | endif 10 | let $1 = 1${3} 11 | snippet f 12 | fun ${1:function_name}(${2}) 13 | ${3:" code} 14 | endf 15 | snippet for 16 | for ${1:needle} in ${2:haystack} 17 | ${3:" code} 18 | endfor 19 | snippet wh 20 | while ${1:condition} 21 | ${2:" code} 22 | endw 23 | snippet if 24 | if ${1:condition} 25 | ${2:" code} 26 | endif 27 | snippet ife 28 | if ${1:condition} 29 | ${2} 30 | else 31 | ${3} 32 | endif 33 | -------------------------------------------------------------------------------- /git/.gitconfig: -------------------------------------------------------------------------------- 1 | [user] 2 | name = Cheng 3 | email = git@zcbenz.com 4 | [push] 5 | default = upstream 6 | [color] 7 | diff = auto 8 | [alias] 9 | lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit 10 | cleanup = "!git branch --merged | grep -v '\\*\\|master' | xargs -n 1 git branch -d" 11 | [hub] 12 | protocol = https 13 | [help] 14 | autocorrect = 1 15 | [http] 16 | sslVerify = false 17 | cookiefile = /Users/zcbenz/.gitcookies 18 | [filter "lfs"] 19 | clean = git-lfs clean %f 20 | smudge = git-lfs smudge %f 21 | required = true 22 | [receive] 23 | denyCurrentBranch = updateInstead 24 | [pull] 25 | rebase = false 26 | [init] 27 | defaultBranch = main 28 | -------------------------------------------------------------------------------- /script/update_hosts: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Root of dotfiles 4 | SOURCE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.." 5 | 6 | # Include utils 7 | source "$SOURCE/script/bash_utils" 8 | 9 | HOSTS="$SOURCE/etc/hosts" 10 | WHERE=${1:-$HOSTS} 11 | 12 | HOST_LEAD='### BEGIN GENERATED DOTFILES CONTENT' 13 | HOST_TAIL='### END GENERATED DOTFILES CONTENT' 14 | if grep -q DOTFILES /etc/hosts; then 15 | sudo $SED -i -e "/$HOST_LEAD/,/$HOST_TAIL/{ /$HOST_LEAD/{p; r $WHERE 16 | }; /$HOST_TAIL/p; d }" /etc/hosts 17 | else 18 | sudo bash -c 'echo >> /etc/hosts' 19 | sudo bash -c "echo \"$HOST_LEAD\" >> /etc/hosts" 20 | sudo bash -c "cat '$WHERE' >> /etc/hosts" 21 | sudo bash -c "echo \"$HOST_TAIL\" >> /etc/hosts" 22 | fi 23 | -------------------------------------------------------------------------------- /vim/.vim/snippets/markdown.snippets: -------------------------------------------------------------------------------- 1 | # [link][] 2 | snippet [] 3 | [${1:link_id}][]${2} 4 | # [link][id] 5 | snippet [[ 6 | [${1:link}][${2:id}]${3} 7 | # [link](url) 8 | snippet [( 9 | [${1:link}](http://${2:url})${3} 10 | # [link](email) 11 | snippet [@ 12 | [${1:link}(mailto:${2:email})${3} 13 | # [link](url "title") 14 | snippet [(" 15 | [${1:link}](${2:url} "${3:title}")${4} 16 | # [id]: url "title" 17 | snippet [: 18 | [${1:id}]: http://${2:url} "${3:title}" 19 | # [id]: email "title" 20 | snippet [:@ 21 | [${1:id}]: mailto:${2:url} "${3:title}" 22 | # ![alt][id] 23 | snippet ![ 24 | ![${1:alt}][${2:id}]${3} 25 | # ![alt](url) 26 | snippet !( 27 | ![${1:alt}](${2:url})${3} 28 | # ![alt](url "title") 29 | snippet !(" 30 | ![${1:alt}](${2:url} "${3:title}")${4} 31 | # *emphasis* or _emphasis_ 32 | snippet * 33 | *${1}*${2} 34 | snippet _ 35 | _${1}_${2} 36 | # **strong** or __strong__ 37 | snippet ** 38 | **${1}**${2} 39 | snippet __ 40 | __${1}__${2} 41 | # `code` 42 | snippet ` 43 | \`${1}\`${2} 44 | -------------------------------------------------------------------------------- /vim/.vim/snippets/mako.snippets: -------------------------------------------------------------------------------- 1 | snippet def 2 | <%def name="${1:name}"> 3 | ${2:} 4 | 5 | snippet call 6 | <%call expr="${1:name}"> 7 | ${2:} 8 | 9 | snippet doc 10 | <%doc> 11 | ${1:} 12 | 13 | snippet text 14 | <%text> 15 | ${1:} 16 | 17 | snippet for 18 | % for ${1:i} in ${2:iter}: 19 | ${3:} 20 | % endfor 21 | snippet if if 22 | % if ${1:condition}: 23 | ${2:} 24 | % endif 25 | snippet if if/else 26 | % if ${1:condition}: 27 | ${2:} 28 | % else: 29 | ${3:} 30 | % endif 31 | snippet try 32 | % try: 33 | ${1:} 34 | % except${2:}: 35 | ${3:pass} 36 | % endtry 37 | snippet wh 38 | % while ${1:}: 39 | ${2:} 40 | % endwhile 41 | snippet $ 42 | ${ ${1:} } 43 | snippet <% 44 | <% ${1:} %> 45 | snippet 47 | snippet inherit 48 | <%inherit file="${1:filename}" /> 49 | snippet include 50 | <%include file="${1:filename}" /> 51 | snippet namespace 52 | <%namespace file="${1:name}" /> 53 | snippet page 54 | <%page args="${1:}" /> 55 | -------------------------------------------------------------------------------- /vim/.vim/snippets/zsh.snippets: -------------------------------------------------------------------------------- 1 | # #!/bin/zsh 2 | snippet #! 3 | #!/bin/zsh 4 | 5 | snippet if 6 | if ${1:condition}; then 7 | ${2:# statements} 8 | fi 9 | snippet ife 10 | if ${1:condition}; then 11 | ${2:# statements} 12 | else 13 | ${3:# statements} 14 | fi 15 | snippet elif 16 | elif ${1:condition} ; then 17 | ${2:# statements} 18 | snippet for 19 | for (( ${2:i} = 0; $2 < ${1:count}; $2++ )); do 20 | ${3:# statements} 21 | done 22 | snippet fore 23 | for ${1:item} in ${2:list}; do 24 | ${3:# statements} 25 | done 26 | snippet wh 27 | while ${1:condition}; do 28 | ${2:# statements} 29 | done 30 | snippet until 31 | until ${1:condition}; do 32 | ${2:# statements} 33 | done 34 | snippet repeat 35 | repeat ${1:integer}; do 36 | ${2:# statements} 37 | done 38 | snippet case 39 | case ${1:word} in 40 | ${2:pattern}) 41 | ${3};; 42 | esac 43 | snippet select 44 | select ${1:answer} in ${2:choices}; do 45 | ${3:# statements} 46 | done 47 | snippet ( 48 | ( ${1:#statements} ) 49 | snippet { 50 | { ${1:#statements} } 51 | snippet [ 52 | [[ ${1:test} ]] 53 | snippet always 54 | { ${1:try} } always { ${2:always} } 55 | snippet fun 56 | function ${1:name} (${2:args}) { 57 | ${3:# body} 58 | } 59 | -------------------------------------------------------------------------------- /bash/.tools_aliases: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export PATH=~/bin:$PATH 4 | 5 | # Convient settings 6 | alias l='ls -p' 7 | alias la='ls -a' 8 | alias ll='ls -lh' 9 | alias df='df -h' 10 | alias sudo='sudo env PATH=$PATH' # sudo with current PATH 11 | alias cn='env LANG=zh_CN.UTF-8 ' 12 | alias gd="git-branch-delete" 13 | alias gs="switch-branch" 14 | alias ur="uv run --no-project" 15 | function mkcd () 16 | { 17 | mkdir $1 && cd $1 18 | } 19 | 20 | # OS specific commands 21 | OS=${OSTYPE//[0-9.]/} # remove trailing version like in darwin9.0 22 | if [[ $OS == 'darwin' ]]; then 23 | export PATH=~/bin/darwin:/usr/local/sbin:/usr/local/bin:$PATH 24 | alias gb="git rev-parse --abbrev-ref HEAD | tee /dev/tty | tr -d '\n' | pbcopy" 25 | alias gh="git rev-parse HEAD | tee /dev/tty | tr -d '\n' | pbcopy" 26 | alias e="~/codes/be/src/out/Default/Electron.app/Contents/MacOS/Electron" 27 | elif [[ $OS == 'linux-gnu' ]]; then 28 | alias open="xdg-open" 29 | alias e="~/codes/be/src/out/Default/electron" 30 | elif [[ $OS == 'cygwin' ]]; then 31 | alias open="cygstart" 32 | alias ls="ls --color" 33 | alias ahk="/cygdrive/c/Program\ Files/AutoHotkey/AutoHotkey.exe" 34 | alias npm="npm.cmd" 35 | alias e="~/codes/be/src/out/Default/electron.exe" 36 | fi 37 | -------------------------------------------------------------------------------- /script/bash_utils: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | progress () { 4 | printf " [ \033[00;34m..\033[0m ] $1\n" 5 | } 6 | 7 | info () { 8 | printf " [\033[0;33mINFO\033[0m] $1\n" 9 | } 10 | 11 | user () { 12 | printf "\r [ \033[0;33m?\033[0m ] $1 " 13 | } 14 | 15 | success () { 16 | printf "\r\033[2K [ \033[00;32mOK\033[0m ] $1\n" 17 | } 18 | 19 | fail () { 20 | printf "\r\033[2K [\033[0;31mFAIL\033[0m] $1\n" 21 | exit 1 22 | } 23 | 24 | function has_command { 25 | if command -v $1 >/dev/null 2>&1 26 | then return 0 27 | else return 1 28 | fi 29 | } 30 | 31 | function cross_install { 32 | if has_command sudo; then 33 | SUDO='sudo ' 34 | else 35 | SUDO='' 36 | fi 37 | 38 | if has_command yum; then 39 | INSTALL="${SUDO}yum install" 40 | elif has_command apt; then 41 | INSTALL="${SUDO}apt install -y" 42 | elif has_command brew; then 43 | INSTALL='brew install' 44 | else 45 | echo 'Cannot find install tool for current platform' 46 | return 1 47 | fi 48 | $INSTALL $1 49 | } 50 | 51 | PLATFORM=${OSTYPE//[0-9.]/} # remove trailing version like in darwin9.0 52 | 53 | case $PLATFORM in 54 | linux-gnu) OS=$(head -n 1 /etc/issue | awk '{ print $1 }') ;; 55 | darwin) OS=OSX ;; 56 | *) OS=OTHER ;; 57 | esac 58 | 59 | # Tools aliases 60 | if [[ $PLATFORM == 'darwin' ]]; then 61 | SED=gsed 62 | else 63 | SED=sed 64 | fi 65 | 66 | -------------------------------------------------------------------------------- /vim/.vim/snippets/autoit.snippets: -------------------------------------------------------------------------------- 1 | snippet if 2 | If ${1:condition} Then 3 | ${2:; True code} 4 | EndIf 5 | snippet el 6 | Else 7 | ${1} 8 | snippet elif 9 | ElseIf ${1:condition} Then 10 | ${2:; True code} 11 | # If/Else block 12 | snippet ifel 13 | If ${1:condition} Then 14 | ${2:; True code} 15 | Else 16 | ${3:; Else code} 17 | EndIf 18 | # If/ElseIf/Else block 19 | snippet ifelif 20 | If ${1:condition 1} Then 21 | ${2:; True code} 22 | ElseIf ${3:condition 2} Then 23 | ${4:; True code} 24 | Else 25 | ${5:; Else code} 26 | EndIf 27 | # Switch block 28 | snippet switch 29 | Switch (${1:condition}) 30 | Case {$2:case1}: 31 | {$3:; Case 1 code} 32 | Case Else: 33 | {$4:; Else code} 34 | EndSwitch 35 | # Select block 36 | snippet select 37 | Select (${1:condition}) 38 | Case {$2:case1}: 39 | {$3:; Case 1 code} 40 | Case Else: 41 | {$4:; Else code} 42 | EndSelect 43 | # While loop 44 | snippet while 45 | While (${1:condition}) 46 | ${2:; code...} 47 | WEnd 48 | # For loop 49 | snippet for 50 | For ${1:n} = ${3:1} to ${2:count} 51 | ${4:; code...} 52 | Next 53 | # New Function 54 | snippet func 55 | Func ${1:fname}(${2:`indent('.') ? 'self' : ''`}): 56 | ${4:Return} 57 | EndFunc 58 | # Message box 59 | snippet msg 60 | MsgBox(${3:MsgType}, ${1:"Title"}, ${2:"Message Text"}) 61 | # Debug Message 62 | snippet debug 63 | MsgBox(0, "Debug", ${1:"Debug Message"}) 64 | # Show Variable Debug Message 65 | snippet showvar 66 | MsgBox(0, "${1:VarName}", $1) 67 | -------------------------------------------------------------------------------- /script/solarize: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Shell script that configures gnome-terminal to use solarized theme 4 | # colors. Written for Ubuntu 11.10, untested on anything else. 5 | # 6 | # Solarized theme: http://ethanschoonover.com/solarized 7 | # 8 | # Adapted from these sources: 9 | # https://gist.github.com/1280177 10 | # http://xorcode.com/guides/solarized-vim-eclipse-ubuntu/ 11 | 12 | case "$1" in 13 | "dark") 14 | PALETTE="#070736364242:#D3D301010202:#858599990000:#B5B589890000:#26268B8BD2D2:#D3D336368282:#2A2AA1A19898:#EEEEE8E8D5D5:#00002B2B3636:#CBCB4B4B1616:#58586E6E7575:#65657B7B8383:#838394949696:#6C6C7171C4C4:#9393A1A1A1A1:#FDFDF6F6E3E3" 15 | BG_COLOR="#00002B2B3636" 16 | FG_COLOR="#65657B7B8383" 17 | ;; 18 | "light") 19 | PALETTE="#EEEEE8E8D5D5:#D3D301010202:#858599990000:#B5B589890000:#26268B8BD2D2:#D3D336368282:#2A2AA1A19898:#070736364242:#FDFDF6F6E3E3:#CBCB4B4B1616:#9393A1A1A1A1:#838394949696:#65657B7B8383:#6C6C7171C4C4:#58586E6E7575:#00002B2B3636" 20 | BG_COLOR="#FDFDF6F6E3E3" 21 | FG_COLOR="#838394949696" 22 | ;; 23 | *) 24 | echo "Usage: solarize [light | dark]" 25 | exit 26 | ;; 27 | esac 28 | 29 | gconftool-2 --set "/apps/gnome-terminal/profiles/Default/use_theme_background" --type bool false 30 | gconftool-2 --set "/apps/gnome-terminal/profiles/Default/use_theme_colors" --type bool false 31 | gconftool-2 --set "/apps/gnome-terminal/profiles/Default/palette" --type string "$PALETTE" 32 | gconftool-2 --set "/apps/gnome-terminal/profiles/Default/background_color" --type string "$BG_COLOR" 33 | gconftool-2 --set "/apps/gnome-terminal/profiles/Default/foreground_color" --type string "$FG_COLOR" 34 | -------------------------------------------------------------------------------- /vim/.vim/snippets/java.snippets: -------------------------------------------------------------------------------- 1 | snippet main 2 | public static void main (String [] args) 3 | { 4 | ${1:/* code */} 5 | } 6 | snippet pu 7 | public 8 | snippet po 9 | protected 10 | snippet pr 11 | private 12 | snippet st 13 | static 14 | snippet fi 15 | final 16 | snippet ab 17 | abstract 18 | snippet re 19 | return 20 | snippet br 21 | break; 22 | snippet de 23 | default: 24 | ${1} 25 | snippet ca 26 | catch(${1:Exception} ${2:e}) ${3} 27 | snippet th 28 | throw 29 | snippet sy 30 | synchronized 31 | snippet im 32 | import 33 | snippet j.u 34 | java.util 35 | snippet j.i 36 | java.io. 37 | snippet j.b 38 | java.beans. 39 | snippet j.n 40 | java.net. 41 | snippet j.m 42 | java.math. 43 | snippet if 44 | if (${1}) ${2} 45 | snippet el 46 | else 47 | snippet elif 48 | else if (${1}) ${2} 49 | snippet wh 50 | while (${1}) ${2} 51 | snippet for 52 | for (${1}; ${2}; ${3}) ${4} 53 | snippet fore 54 | for (${1} : ${2}) ${3} 55 | snippet sw 56 | switch (${1}) ${2} 57 | snippet cs 58 | case ${1}: 59 | ${2} 60 | ${3} 61 | snippet tc 62 | public class ${1:`Filename()`} extends ${2:TestCase} 63 | snippet t 64 | public void test${1:Name}() throws Exception ${2} 65 | snippet cl 66 | class ${1:`Filename("", "untitled")`} ${2} 67 | snippet in 68 | interface ${1:`Filename("", "untitled")`} ${2:extends Parent}${3} 69 | snippet m 70 | ${1:void} ${2:method}(${3}) ${4:throws }${5} 71 | snippet v 72 | ${1:String} ${2:var}${3: = null}${4};${5} 73 | snippet co 74 | static public final ${1:String} ${2:var} = ${3};${4} 75 | snippet cos 76 | static public final String ${1:var} = "${2}";${3} 77 | snippet as 78 | assert ${1:test} : "${2:Failure message}";${3} 79 | -------------------------------------------------------------------------------- /vim/.vim/snippets/javascript.snippets: -------------------------------------------------------------------------------- 1 | # Prototype 2 | snippet proto 3 | ${1:class_name}.prototype.${2:method_name} = 4 | function(${3:first_argument}) { 5 | ${4:// body...} 6 | }; 7 | # Function 8 | snippet fun 9 | function ${1:function_name} (${2:argument}) { 10 | ${3:// body...} 11 | } 12 | # Anonymous Function 13 | snippet f 14 | function(${1}) {${2}}; 15 | # if 16 | snippet if 17 | if (${1:true}) {${2}}; 18 | # if ... else 19 | snippet ife 20 | if (${1:true}) {${2}} 21 | else{${3}}; 22 | # tertiary conditional 23 | snippet t 24 | ${1:/* condition */} ? ${2:a} : ${3:b} 25 | # switch 26 | snippet switch 27 | switch(${1:expression}) { 28 | case '${3:case}': 29 | ${4:// code} 30 | break; 31 | ${5} 32 | default: 33 | ${2:// code} 34 | } 35 | # case 36 | snippet case 37 | case '${1:case}': 38 | ${2:// code} 39 | break; 40 | ${3} 41 | # for (...) {...} 42 | snippet for 43 | for (var ${2:i} = 0; $2 < ${1:Things}.length; $2${3:++}) { 44 | ${4:$1[$2]} 45 | }; 46 | # for (...) {...} (Improved Native For-Loop) 47 | snippet forr 48 | for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2${3:--}) { 49 | ${4:$1[$2]} 50 | }; 51 | # while (...) {...} 52 | snippet wh 53 | while (${1:/* condition */}) { 54 | ${2:/* code */} 55 | } 56 | # do...while 57 | snippet do 58 | do { 59 | ${2:/* code */} 60 | } while (${1:/* condition */}); 61 | # Object Method 62 | snippet :f 63 | ${1:method_name}: function(${2:attribute}) { 64 | ${4} 65 | }${3:,} 66 | # setTimeout function 67 | snippet timeout 68 | setTimeout(function() {${3}}${2}, ${1:10}; 69 | # Get Elements 70 | snippet get 71 | getElementsBy${1:TagName}('${2}')${3} 72 | # Get Element 73 | snippet gett 74 | getElementBy${1:Id}('${2}')${3} 75 | -------------------------------------------------------------------------------- /vim/.vim/snippets/tcl.snippets: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/tclsh 2 | snippet #! 3 | #!/usr/bin/tclsh 4 | 5 | # Process 6 | snippet pro 7 | proc ${1:function_name} {${2:args}} { 8 | ${3:#body ...} 9 | } 10 | #xif 11 | snippet xif 12 | ${1:expr}? ${2:true} : ${3:false} 13 | # Conditional 14 | snippet if 15 | if {${1}} { 16 | ${2:# body...} 17 | } 18 | # Conditional if..else 19 | snippet ife 20 | if {${1}} { 21 | ${2:# body...} 22 | } else { 23 | ${3:# else...} 24 | } 25 | # Conditional if..elsif..else 26 | snippet ifee 27 | if {${1}} { 28 | ${2:# body...} 29 | } elseif {${3}} { 30 | ${4:# elsif...} 31 | } else { 32 | ${5:# else...} 33 | } 34 | # If catch then 35 | snippet ifc 36 | if { [catch {${1:#do something...}} ${2:err}] } { 37 | ${3:# handle failure...} 38 | } 39 | # Catch 40 | snippet catch 41 | catch {${1}} ${2:err} ${3:options} 42 | # While Loop 43 | snippet wh 44 | while {${1}} { 45 | ${2:# body...} 46 | } 47 | # For Loop 48 | snippet for 49 | for {set ${2:var} 0} {$$2 < ${1:count}} {${3:incr} $2} { 50 | ${4:# body...} 51 | } 52 | # Foreach Loop 53 | snippet fore 54 | foreach ${1:x} {${2:#list}} { 55 | ${3:# body...} 56 | } 57 | # after ms script... 58 | snippet af 59 | after ${1:ms} ${2:#do something} 60 | # after cancel id 61 | snippet afc 62 | after cancel ${1:id or script} 63 | # after idle 64 | snippet afi 65 | after idle ${1:script} 66 | # after info id 67 | snippet afin 68 | after info ${1:id} 69 | # Expr 70 | snippet exp 71 | expr {${1:#expression here}} 72 | # Switch 73 | snippet sw 74 | switch ${1:var} { 75 | ${3:pattern 1} { 76 | ${4:#do something} 77 | } 78 | default { 79 | ${2:#do something} 80 | } 81 | } 82 | # Case 83 | snippet ca 84 | ${1:pattern} { 85 | ${2:#do something} 86 | }${3} 87 | # Namespace eval 88 | snippet ns 89 | namespace eval ${1:path} {${2:#script...}} 90 | # Namespace current 91 | snippet nsc 92 | namespace current 93 | -------------------------------------------------------------------------------- /vim/.vim/snippets/perl.snippets: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/perl 2 | snippet #! 3 | #!/usr/bin/perl 4 | 5 | # Hash Pointer 6 | snippet . 7 | => 8 | # Function 9 | snippet sub 10 | sub ${1:function_name} { 11 | ${2:#body ...} 12 | } 13 | # Conditional 14 | snippet if 15 | if (${1}) { 16 | ${2:# body...} 17 | } 18 | # Conditional if..else 19 | snippet ife 20 | if (${1}) { 21 | ${2:# body...} 22 | } else { 23 | ${3:# else...} 24 | } 25 | # Conditional if..elsif..else 26 | snippet ifee 27 | if (${1}) { 28 | ${2:# body...} 29 | } elsif (${3}) { 30 | ${4:# elsif...} 31 | } else { 32 | ${5:# else...} 33 | } 34 | # Conditional One-line 35 | snippet xif 36 | ${1:expression} if ${2:condition};${3} 37 | # Unless conditional 38 | snippet unless 39 | unless (${1}) { 40 | ${2:# body...} 41 | } 42 | # Unless conditional One-line 43 | snippet xunless 44 | ${1:expression} unless ${2:condition};${3} 45 | # Try/Except 46 | snippet eval 47 | eval { 48 | ${1:# do something risky...} 49 | }; 50 | if ($@) { 51 | ${2:# handle failure...} 52 | } 53 | # While Loop 54 | snippet wh 55 | while (${1}) { 56 | ${2:# body...} 57 | } 58 | # While Loop One-line 59 | snippet xwh 60 | ${1:expression} while ${2:condition};${3} 61 | # For Loop 62 | snippet for 63 | for (my $${2:var} = 0; $$2 < ${1:count}; $$2${3:++}) { 64 | ${4:# body...} 65 | } 66 | # Foreach Loop 67 | snippet fore 68 | foreach my $${1:x} (@${2:array}) { 69 | ${3:# body...} 70 | } 71 | # Foreach Loop One-line 72 | snippet xfore 73 | ${1:expression} foreach @${2:array};${3} 74 | # Package 75 | snippet cl 76 | package ${1:ClassName}; 77 | 78 | use base qw(${2:ParentClass}); 79 | 80 | sub new { 81 | my $class = shift; 82 | $class = ref $class if ref $class; 83 | my $self = bless {}, $class; 84 | $self; 85 | } 86 | 87 | 1;${3} 88 | # Read File 89 | snippet slurp 90 | my $${1:var}; 91 | { local $/ = undef; local *FILE; open FILE, "<${2:file}"; $$1 = ; close FILE }${3} 92 | -------------------------------------------------------------------------------- /vim/.vim/snippets/python.snippets: -------------------------------------------------------------------------------- 1 | snippet #! 2 | #!/usr/bin/python 3 | 4 | snippet imp 5 | import ${1:module} 6 | # Module Docstring 7 | snippet docs 8 | ''' 9 | File: ${1:`Filename('$1.py', 'foo.py')`} 10 | Author: ${2:`g:snips_author`} 11 | Description: ${3} 12 | ''' 13 | snippet wh 14 | while ${1:condition}: 15 | ${2:# code...} 16 | snippet for 17 | for ${1:needle} in ${2:haystack}: 18 | ${3:# code...} 19 | # New Class 20 | snippet cl 21 | class ${1:ClassName}(${2:object}): 22 | """${3:docstring for $1}""" 23 | def __init__(self, ${4:arg}): 24 | ${5:super($1, self).__init__()} 25 | self.$4 = $4 26 | ${6} 27 | # New Function 28 | snippet def 29 | def ${1:fname}(${2:`indent('.') ? 'self' : ''`}): 30 | """${3:docstring for $1}""" 31 | ${4:pass} 32 | snippet deff 33 | def ${1:fname}(${2:`indent('.') ? 'self' : ''`}): 34 | ${3} 35 | # New Method 36 | snippet defs 37 | def ${1:mname}(self, ${2:arg}): 38 | ${3:pass} 39 | # New Property 40 | snippet property 41 | def ${1:foo}(): 42 | doc = "${2:The $1 property.}" 43 | def fget(self): 44 | ${3:return self._$1} 45 | def fset(self, value): 46 | ${4:self._$1 = value} 47 | # Lambda 48 | snippet ld 49 | ${1:var} = lambda ${2:vars} : ${3:action} 50 | snippet . 51 | self. 52 | snippet try Try/Except 53 | try: 54 | ${1:pass} 55 | except ${2:Exception}, ${3:e}: 56 | ${4:raise $3} 57 | snippet try Try/Except/Else 58 | try: 59 | ${1:pass} 60 | except ${2:Exception}, ${3:e}: 61 | ${4:raise $3} 62 | else: 63 | ${5:pass} 64 | snippet try Try/Except/Finally 65 | try: 66 | ${1:pass} 67 | except ${2:Exception}, ${3:e}: 68 | ${4:raise $3} 69 | finally: 70 | ${5:pass} 71 | snippet try Try/Except/Else/Finally 72 | try: 73 | ${1:pass} 74 | except ${2:Exception}, ${3:e}: 75 | ${4:raise $3} 76 | else: 77 | ${5:pass} 78 | finally: 79 | ${6:pass} 80 | # if __name__ == '__main__': 81 | snippet ifmain 82 | if __name__ == '__main__': 83 | ${1:main()} 84 | # __magic__ 85 | snippet _ 86 | __${1:init}__${2} 87 | -------------------------------------------------------------------------------- /vim/.vimrc: -------------------------------------------------------------------------------- 1 | syntax on 2 | set nocompatible 3 | set smartindent 4 | set nobackup 5 | set number 6 | set nowrap 7 | set laststatus=2 8 | set statusline=%<%t\%h%m%r%=%10.(line=%l\ \ col=%c%V\ \ totlin=%L%)\ \ \%=%(bytval=0x%B,%n%Y%)\ \ \%P 9 | set equalprg=indent\ -npro\ -kr\ -i8\ -ts8\ -sob\ -l80\ -ss\ -ncs\ -cp1 10 | set matchpairs+=<:>,":" 11 | set nohlsearch 12 | set autochdir 13 | set incsearch 14 | set expandtab 15 | set tabstop=2 16 | set shiftwidth=2 17 | set scrolloff=2 18 | set fdm=marker 19 | set t_Co=256 20 | set fileencodings=utf-8,gbk,ucs-bom,cp936 21 | 22 | " let esc have no delay 23 | set timeoutlen=1000 ttimeoutlen=0 24 | 25 | set visualbell " don't beep 26 | set noerrorbells " don't beep 27 | set history=1000 " remember more commands and search history 28 | set undolevels=1000 " use many muchos levels of undo 29 | 30 | filetype plugin on 31 | filetype indent on 32 | 33 | " tabpage binding 34 | nnoremap 1 1gt 35 | nnoremap 2 2gt 36 | nnoremap 3 3gt 37 | nnoremap 4 4gt 38 | nnoremap 5 5gt 39 | nnoremap 6 6gt 40 | nnoremap 7 7gt 41 | nnoremap 8 8gt 42 | nnoremap 9 9gt 43 | nnoremap t :tabnew 44 | nnoremap c :tabclose 45 | nnoremap w :bw 46 | nnoremap a :wa 47 | nnoremap q :qa 48 | 49 | let &termencoding=&encoding 50 | 51 | " allow MRU command 52 | let g:fuf_modesDisable = [] 53 | 54 | " don't report error of C++ lambadas 55 | let c_no_curly_error=1 56 | 57 | " ignore files in .gitignore in ctrlp 58 | let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard'] 59 | " ignore temp files in mru 60 | let g:ctrlp_mruf_exclude = '/tmp/.*\|/var/folders/.*|/private/var/folders/.*' 61 | 62 | " key maps 63 | nnoremap g :CtrlPMRU 64 | nnoremap f :CtrlP 65 | 66 | " use flavored-markdown by default 67 | augroup markdown 68 | au! 69 | au BufNewFile,BufRead *.md,*.markdown setlocal filetype=ghmarkdown 70 | augroup END 71 | 72 | " map .mm to Objective-C++ 73 | autocmd BufNewFile,BufRead *.mm set syntax=objcpp 74 | 75 | " load c++ snippets in cuda 76 | let g:snipMate = get(g:, 'snipMate', {}) 77 | let g:snipMate.scope_aliases = {} 78 | let g:snipMate.scope_aliases['cuda'] = 'cpp' 79 | 80 | call pathogen#infect() 81 | -------------------------------------------------------------------------------- /bash/.bashrc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Extra tools 4 | source ~/.tools_aliases 5 | 6 | # Suppress the zsh warning 7 | export BASH_SILENCE_DEPRECATION_WARNING=1 8 | 9 | # Bash settings 10 | export CLICOLOR=1 11 | export HISTSIZE=3000 12 | export HISTCONTROL=ignoreboth 13 | export HISTTIMEFORMAT='%F %T ' 14 | shopt -s histappend 15 | shopt -s checkwinsize 16 | 17 | # Set variable identifying the chroot you work in. 18 | if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then 19 | debian_chroot=$(cat /etc/debian_chroot) 20 | fi 21 | 22 | # Host name. 23 | if [ -z "$BOLT_TASK_ID" ]; then 24 | COMPUTER_NAME=`hostname -s` 25 | else 26 | COMPUTER_NAME="bolt-$BOLT_TASK_ID" 27 | fi 28 | 29 | # kitten:~$ 30 | if [[ "$OS" != 'cygwin' ]]; then 31 | if [ "$COMPUTER_NAME" == "air" ]; then 32 | HOST_COLOR="[0;30m" # Black 33 | else 34 | HOST_COLOR="[0;35m" # Magenta color for remote hosts 35 | fi 36 | PS1='${debian_chroot:+($debian_chroot)}\[\e$HOST_COLOR\]$COMPUTER_NAME\[\e[m\]:\w\[\e[0;$(($? == 0 ? 33 : 31))m\]\$\[\e[m\] ' 37 | fi 38 | 39 | # I use vim! 40 | set -o vi 41 | export EDITOR=vim 42 | alias vi="vim -p" 43 | 44 | # Quick move between folders. 45 | export MARKPATH=$HOME/.marks 46 | function jump { 47 | cd -P $MARKPATH/$1 2> /dev/null || echo "No such mark: $1" 48 | } 49 | function mark { 50 | mkdir -p $MARKPATH; ln -s "$(pwd)" $MARKPATH/$1 51 | } 52 | function unmark { 53 | rm -i $MARKPATH/$1 54 | } 55 | function marks { 56 | (t="$(printf "\t")"; cd $MARKPATH && stat -f"%N$t%SY" * | column -ts"$t") 57 | } 58 | function _jump { 59 | local cur=${COMP_WORDS[COMP_CWORD]} 60 | local marks=$(find $MARKPATH -type l | awk -F '/' '{print $NF}') 61 | COMPREPLY=($(compgen -W '${marks[@]}' -- "$cur")) 62 | return 0 63 | } 64 | complete -o default -o nospace -F _jump jump 65 | 66 | # OS specific commands 67 | if [[ $OS == 'linux-gnu' ]]; then 68 | source /usr/share/autojump/autojump.sh 69 | elif [[ $OS == 'darwin' ]]; then 70 | [ -f /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)" 71 | [ -f /opt/homebrew/etc/profile.d/autojump.sh ] && . /opt/homebrew/etc/profile.d/autojump.sh 72 | elif [[ $OS == 'cygwin' ]]; then 73 | export LC_ALL='en_US.UTF-8' 74 | # Force UTF-8 code page. 75 | chcp.com 437 > /dev/null 76 | fi 77 | 78 | # Import secrect environments 79 | if [ -e "$HOME/bin/set-env" ]; then 80 | source "$HOME/bin/set-env" 81 | fi 82 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vim/.vim/bundle/markdown"] 2 | path = vim/.vim/bundle/markdown 3 | url = git@github.com:tpope/vim-markdown.git 4 | [submodule "vim/.vim/bundle/github-flavored-markdown"] 5 | path = vim/.vim/bundle/github-flavored-markdown 6 | url = https://github.com/jtratner/vim-flavored-markdown 7 | [submodule "vim/.vim/bundle/acp"] 8 | path = vim/.vim/bundle/acp 9 | url = https://github.com/vim-scripts/AutoComplPop.git 10 | [submodule "vim/.vim/bundle/enhanced-commentify"] 11 | path = vim/.vim/bundle/enhanced-commentify 12 | url = https://github.com/vim-scripts/EnhCommentify.vim.git 13 | [submodule "vim/.vim/bundle/splitjoin"] 14 | path = vim/.vim/bundle/splitjoin 15 | url = https://github.com/AndrewRadev/splitjoin.vim 16 | [submodule "vim/.vim/bundle/trailing-whitespace"] 17 | path = vim/.vim/bundle/trailing-whitespace 18 | url = https://github.com/bronson/vim-trailing-whitespace.git 19 | [submodule "vim/.vim/bundle/vim-snipmate"] 20 | path = vim/.vim/bundle/vim-snipmate 21 | url = https://github.com/garbas/vim-snipmate.git 22 | [submodule "vim/.vim/bundle/tlib_vim"] 23 | path = vim/.vim/bundle/tlib_vim 24 | url = https://github.com/tomtom/tlib_vim.git 25 | [submodule "vim/.vim/bundle/vim-addon-mw-utils"] 26 | path = vim/.vim/bundle/vim-addon-mw-utils 27 | url = https://github.com/MarcWeber/vim-addon-mw-utils.git 28 | [submodule "vim/.vim/bundle/L9"] 29 | path = vim/.vim/bundle/L9 30 | url = https://github.com/vim-scripts/L9.git 31 | [submodule "vim/.vim/bundle/vim-cpp-enhanced-highlight"] 32 | path = vim/.vim/bundle/vim-cpp-enhanced-highlight 33 | url = https://github.com/octol/vim-cpp-enhanced-highlight.git 34 | [submodule "vim/.vim/bundle/vim-gn"] 35 | path = vim/.vim/bundle/vim-gn 36 | url = https://github.com/c0nk/vim-gn 37 | [submodule "vim/.vim/bundle/vim-javascript"] 38 | path = vim/.vim/bundle/vim-javascript 39 | url = https://github.com/pangloss/vim-javascript 40 | [submodule "vim/.vim/bundle/vim-pug"] 41 | path = vim/.vim/bundle/vim-pug 42 | url = https://github.com/digitaltoad/vim-pug 43 | [submodule "vim/.vim/bundle/ctrlp"] 44 | path = vim/.vim/bundle/ctrlp 45 | url = https://github.com/ctrlpvim/ctrlp.vim 46 | [submodule "vim/.vim/bundle/vim-typescript"] 47 | path = vim/.vim/bundle/vim-typescript 48 | url = https://github.com/leafgarland/typescript-vim 49 | [submodule "vim/.vim/bundle/vim-wgsl"] 50 | path = vim/.vim/bundle/vim-wgsl 51 | url = https://github.com/DingDean/wgsl.vim 52 | -------------------------------------------------------------------------------- /vim/.vim/snippets/tex.snippets: -------------------------------------------------------------------------------- 1 | # \begin{}...\end{} 2 | snippet begin 3 | \begin{${1:env}} 4 | ${2} 5 | \end{$1} 6 | # Tabular 7 | snippet tab 8 | \begin{${1:tabular}}{${2:c}} 9 | ${3} 10 | \end{$1} 11 | # Align(ed) 12 | snippet ali 13 | \begin{align${1:ed}} 14 | ${2} 15 | \end{align$1} 16 | # Gather(ed) 17 | snippet gat 18 | \begin{gather${1:ed}} 19 | ${2} 20 | \end{gather$1} 21 | # Equation 22 | snippet eq 23 | \begin{equation} 24 | ${1} 25 | \end{equation} 26 | # Unnumbered Equation 27 | snippet \ 28 | \\[ 29 | ${1} 30 | \\] 31 | # Enumerate 32 | snippet enum 33 | \begin{enumerate} 34 | \item ${1} 35 | \end{enumerate} 36 | # Itemize 37 | snippet item 38 | \begin{itemize} 39 | \item ${1} 40 | \end{itemize} 41 | # Description 42 | snippet desc 43 | \begin{description} 44 | \item[${1}] ${2} 45 | \end{description} 46 | # Matrix 47 | snippet mat 48 | \begin{${1:p/b/v/V/B/small}matrix} 49 | ${2} 50 | \end{$1matrix} 51 | # Cases 52 | snippet cas 53 | \begin{cases} 54 | ${1:equation}, &\text{ if }${2:case}\\ 55 | ${3} 56 | \end{cases} 57 | # Split 58 | snippet spl 59 | \begin{split} 60 | ${1} 61 | \end{split} 62 | # Part 63 | snippet part 64 | \part{${1:part name}} % (fold) 65 | \label{prt:${2:$1}} 66 | ${3} 67 | % part $2 (end) 68 | # Chapter 69 | snippet cha 70 | \chapter{${1:chapter name}} % (fold) 71 | \label{cha:${2:$1}} 72 | ${3} 73 | % chapter $2 (end) 74 | # Section 75 | snippet sec 76 | \section{${1:section name}} % (fold) 77 | \label{sec:${2:$1}} 78 | ${3} 79 | % section $2 (end) 80 | # Sub Section 81 | snippet sub 82 | \subsection{${1:subsection name}} % (fold) 83 | \label{sub:${2:$1}} 84 | ${3} 85 | % subsection $2 (end) 86 | # Sub Sub Section 87 | snippet subs 88 | \subsubsection{${1:subsubsection name}} % (fold) 89 | \label{ssub:${2:$1}} 90 | ${3} 91 | % subsubsection $2 (end) 92 | # Paragraph 93 | snippet par 94 | \paragraph{${1:paragraph name}} % (fold) 95 | \label{par:${2:$1}} 96 | ${3} 97 | % paragraph $2 (end) 98 | # Sub Paragraph 99 | snippet subp 100 | \subparagraph{${1:subparagraph name}} % (fold) 101 | \label{subp:${2:$1}} 102 | ${3} 103 | % subparagraph $2 (end) 104 | snippet itd 105 | \item[${1:description}] ${2:item} 106 | snippet figure 107 | ${1:Figure}~\ref{${2:fig:}}${3} 108 | snippet table 109 | ${1:Table}~\ref{${2:tab:}}${3} 110 | snippet listing 111 | ${1:Listing}~\ref{${2:list}}${3} 112 | snippet section 113 | ${1:Section}~\ref{${2:sec:}}${3} 114 | snippet page 115 | ${1:page}~\pageref{${2}}${3} 116 | -------------------------------------------------------------------------------- /script/update_node: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if ! DOWNLOAD_PAGE=$(curl -s https://nodejs.org/dist/latest/); then 4 | exit 1; 5 | fi 6 | 7 | NODE_VERSION='v22.17.0' 8 | 9 | NODE_VERSION=$(echo "$DOWNLOAD_PAGE" | grep -o 'node-v[^-]*' \ 10 | | head -1 \ 11 | | awk -F 'node-|.tar.gz' '{print $2}' \ 12 | | cut -d'-' -f 1) 13 | 14 | # Test system's node version if we have node installed 15 | if command -v node >/dev/null 2>&1; then 16 | SYSTEM_NODE_VERSION=`node -v` 17 | NODE_POSITION=`which node` 18 | else 19 | SYSTEM_NODE_VERSION='v0.0.0' 20 | NODE_POSITION='/usr/local/bin/node.exe' 21 | fi 22 | 23 | # Trim spaces 24 | SYSTEM_NODE_VERSION=`echo $SYSTEM_NODE_VERSION | sed 's/^ *\(.*\) *$/\1/'` 25 | 26 | if [[ $NODE_VERSION != $SYSTEM_NODE_VERSION ]]; then 27 | case $OSTYPE in 28 | darwin*) NODE_PLATFORM=darwin ;; 29 | linux*) NODE_PLATFORM=linux ;; 30 | cygwin*) NODE_PLATFORM=cygwin ;; 31 | *) echo "Unsupported platform $OSTYPE" && exit 1 ;; 32 | esac 33 | 34 | if [[ $NODE_PLATFORM == 'cygwin' ]]; then 35 | if echo $PROGRAMFILES | grep 'x86' > /dev/null ; then 36 | NODE_ARCH=x64 37 | else 38 | NODE_ARCH=x86 39 | fi 40 | else 41 | if uname -a | grep 'x86_64' > /dev/null ; then 42 | NODE_ARCH=x64 43 | elif uname -a | grep 'arm64' > /dev/null ; then 44 | NODE_ARCH=arm64 45 | else 46 | NODE_ARCH=x86 47 | fi 48 | fi 49 | 50 | # Download node and untar 51 | if [[ $NODE_PLATFORM == 'cygwin' ]]; then 52 | NODE_DIST_NAME="node-$NODE_VERSION-$NODE_ARCH" 53 | NODE_TARBALL_URL="http://nodejs.org/dist/$NODE_VERSION/$NODE_ARCH/$NODE_DIST_NAME.msi" 54 | else 55 | NODE_DIST_NAME="node-$NODE_VERSION-$NODE_PLATFORM-$NODE_ARCH" 56 | NODE_TARBALL_URL="http://nodejs.org/dist/$NODE_VERSION/$NODE_DIST_NAME.tar.gz" 57 | fi 58 | 59 | TEMP_DIR=`mktemp -d /tmp/dotfiles_node_XXXXXX` 60 | trap "rm -rf $TEMP_DIR" EXIT 61 | cd "$TEMP_DIR" 62 | 63 | if [[ $NODE_PLATFORM == 'cygwin' ]]; then 64 | curl $NODE_TARBALL_URL > node.msi || exit 1 65 | msiexec /package node.msi /passive 66 | else 67 | curl -fsSkL $NODE_TARBALL_URL | tar -zx || exit 1 68 | 69 | # Install 70 | rm $NODE_DIST_NAME/CHANGELOG.md 71 | rm $NODE_DIST_NAME/LICENSE 72 | rm $NODE_DIST_NAME/README.md 73 | if [ $(id -u) -ne 0 ]; then 74 | sudo cp -r $NODE_DIST_NAME/* /usr/local/ || exit 1 75 | else 76 | cp -r $NODE_DIST_NAME/* /usr/local/ || exit 1 77 | fi 78 | fi 79 | 80 | # Clean 81 | if [[ $NODE_PLATFORM != 'cygwin' ]]; then 82 | rm -rf $NODE_DIST_NAME 83 | cd - > /dev/null 84 | fi 85 | fi 86 | -------------------------------------------------------------------------------- /vim/.vim/snippets/c.snippets: -------------------------------------------------------------------------------- 1 | # main() 2 | snippet main 3 | int main(int argc, const char *argv[]) 4 | { 5 | ${0} 6 | return 0; 7 | } 8 | # #include <...> 9 | snippet Inc 10 | #include <${1:stdio.h}>${2} 11 | # #include "..." 12 | snippet inc 13 | #include "${1:`strpart(strpart(expand('%:p'), 0, strridx(expand('%:p'), '.')), strlen(system('git rev-parse --show-toplevel'))).'.h'`}"${2} 14 | # #ifndef ... #define ... #endif 15 | snippet Def 16 | #ifndef $1 17 | #define ${1:SYMBOL} ${2:value} 18 | #endif${3} 19 | snippet def 20 | #define 21 | snippet ifdef 22 | #ifdef ${1:FOO} 23 | ${2:#define } 24 | #endif 25 | snippet #if 26 | #if ${1:FOO} 27 | ${2} 28 | #endif 29 | # Header Include-Guard 30 | # (the randomizer code is taken directly from TextMate; it could probably be 31 | # cleaner, I don't know how to do it in vim script) 32 | snippet once 33 | #ifndef ${1:`toupper(strpart(substitute(expand('%:p'), '/\|\\\|\.', '_', 'g'), strlen(system('git rev-parse --show-toplevel'))).'_')`} 34 | #define $1 35 | 36 | ${0} 37 | 38 | #endif // $1 39 | # If Condition 40 | snippet if 41 | if (${1:/* condition */}) { 42 | ${0:/* code */} 43 | } 44 | snippet el 45 | else { 46 | ${1} 47 | } 48 | # Tertiary conditional 49 | snippet t 50 | ${1:/* condition */} ? ${2:a} : ${3:b} 51 | # Do While Loop 52 | snippet do 53 | do { 54 | ${2:/* code */} 55 | } while (${1:/* condition */}); 56 | # While Loop 57 | snippet wh 58 | while (${1:/* condition */}) { 59 | ${2:/* code */} 60 | } 61 | # For Loop 62 | snippet for 63 | for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) { 64 | ${4:/* code */} 65 | } 66 | # Custom For Loop 67 | snippet forr 68 | for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) { 69 | ${5:/* code */} 70 | } 71 | # Function 72 | snippet fun 73 | ${1:void} ${2:function_name}(${3}) 74 | { 75 | ${4:/* code */} 76 | } 77 | # Function Declaration 78 | snippet fund 79 | ${1:void} ${2:function_name}(${3});${4} 80 | # Typedef 81 | snippet td 82 | typedef ${1:int} ${2:MyCustomType};${3} 83 | # Struct 84 | snippet st 85 | struct ${1:`Filename('$1_t', 'name')`} { 86 | ${2:/* data */} 87 | }${3: /* optional variable list */};${4} 88 | # Typedef struct 89 | snippet tds 90 | typedef struct ${2:_$1 }{ 91 | ${3:/* data */} 92 | } ${1:`Filename('$1_t', 'name')`}; 93 | # Typdef enum 94 | snippet tde 95 | typedef enum { 96 | ${1:/* data */} 97 | } ${2:foo}; 98 | # printf 99 | # unfortunately version this isn't as nice as TextMates's, given the lack of a 100 | # dynamic `...` 101 | snippet pr 102 | printf("${1:%s}\n"${2});${3} 103 | # fprintf (again, this isn't as nice as TextMate's version, but it works) 104 | snippet fpr 105 | fprintf(${1:stderr}, "${2:%s}\n"${3});${4} 106 | snippet . 107 | [${1}]${2} 108 | snippet un 109 | unsigned 110 | -------------------------------------------------------------------------------- /bin/vn: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | responses_yes = ['y', 'yes', 'Y'] 4 | responses_no = ['n', 'no', 'N'] 5 | 6 | import sys, os, shlex, tempfile 7 | 8 | if len(sys.argv) == 1 or '-h' in sys.argv or '--help' in sys.argv: 9 | print('''Usage: 10 | {self} [-iyh] file1 [file2 ...] 11 | 12 | It creates a temporary file and opens Vim. There you edit each name as you 13 | wish, but keep each file on its own line (the line number works as an ID for 14 | the file, so if you put a filename on the wrong line number, a different file 15 | will be renamed!). Then just :wq and ViNamer will perform the renames and clean 16 | up the temp file. 17 | 18 | ViNamer will print each rename operation it performs, so even if you made a 19 | mistake, you can see how each file was renamed. 20 | 21 | Options: 22 | -i 23 | Interactive mode, where you are asked to confirm each rename individually. 24 | Recommended when you first use it. 25 | 26 | -c 27 | Show a summary and ask for confirmation after exiting Vim. 28 | Recommended the second time you use it. To cancel renaming, you can also 29 | just undo your changes (`u` in Vim) and then `:q`. ViNamer will tell you 30 | that the file was not changed and exits without any renames. 31 | 32 | -h --help 33 | Show this help text and exit 34 | 35 | Note that options must be before filenames. This also means that you don't 36 | need -- to separate options from filenames. 37 | 38 | Example usage: 39 | {self} -i /tmp/* 40 | 41 | Copyright 2019 Luc Gommans, distributed as GPLv3: see the `LICENSE` file. 42 | '''.format(self = sys.argv[0])) 43 | exit(1) 44 | 45 | confirmChanges = False 46 | confirmEachChange = False 47 | if sys.argv[1] == '-c': 48 | confirmChanges = True 49 | sys.argv = sys.argv[1:] 50 | elif sys.argv[1] == '-i': 51 | confirmChanges = False 52 | confirmEachChange = True 53 | sys.argv = sys.argv[1:] 54 | 55 | f = tempfile.NamedTemporaryFile(prefix='tmp-virenamer-', delete=False, mode='w') 56 | path = f.name 57 | f.write('\n'.join(sys.argv[1:])) 58 | f.close() 59 | 60 | os.system("vim " + path) 61 | 62 | f = open(path) 63 | renamed = f.read().strip().split('\n') 64 | f.close() 65 | os.unlink(path) 66 | 67 | if len(renamed) != len(sys.argv) - 1: 68 | print('Error: edited file has a different number of lines.') 69 | print('Please read the help text to understand how this tool works.') 70 | exit(2) 71 | 72 | changed = 0 73 | for i, arg in enumerate(sys.argv[1:]): 74 | if arg != renamed[i]: 75 | changed += 1 76 | 77 | if changed == 0: 78 | print('You did not make any changes.') 79 | exit(0) 80 | 81 | if confirmChanges: 82 | response = input('You edited {}/{} lines. Do you want to continue? [y/n] ' 83 | .format(changed, len(sys.argv) - 1)) 84 | if response not in responses_yes: 85 | if response not in responses_no: 86 | print('Accepted responses are y, n, Y, N, yes and no. Exiting.') 87 | exit(1) 88 | else: 89 | print('You chose to discard your changes.') 90 | exit(0) 91 | 92 | for i, arg in enumerate(sys.argv[1:]): 93 | if arg == renamed[i]: 94 | print('Unchanged: "{}"'.format(arg)) 95 | else: 96 | if confirmEachChange: 97 | response = input('Confirm renaming "{}" to "{}"? [y/n/Ctrl+C] '.format(arg, renamed[i])) 98 | if response not in responses_yes: 99 | if response not in responses_no: 100 | print('Accepted responses are y, n, Y, N, yes and no. Exiting.') 101 | exit(1) 102 | else: 103 | print('Not renamed.') 104 | continue 105 | 106 | print('Renaming "{}" to "{}".'.format(arg, renamed[i])) 107 | os.rename(arg, renamed[i]) 108 | 109 | -------------------------------------------------------------------------------- /vim/.vim/snippets/objc.snippets: -------------------------------------------------------------------------------- 1 | # #import <...> 2 | snippet Imp 3 | #import <${1:Cocoa/Cocoa.h}>${2} 4 | # #import "..." 5 | snippet imp 6 | #import "${1:`Filename()`.h}"${2} 7 | # @selector(...) 8 | snippet sel 9 | @selector(${1:method}:)${3} 10 | # @"..." string 11 | snippet s 12 | @"${1}"${2} 13 | # Object 14 | snippet o 15 | ${1:NSObject} *${2:foo} = [${3:$1 alloc}]${4};${5} 16 | # NSLog(...) 17 | snippet log 18 | NSLog(@"${1:%@}"${2});${3} 19 | # Class 20 | snippet objc 21 | @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject} 22 | { 23 | } 24 | @end 25 | 26 | @implementation $1 27 | ${3} 28 | @end 29 | # Class Interface 30 | snippet int 31 | @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject} 32 | {${3} 33 | } 34 | ${4} 35 | @end 36 | # Class Implementation 37 | snippet impl 38 | @implementation ${1:`Filename('', 'someClass')`} 39 | ${2} 40 | @end 41 | snippet init 42 | - (id)init 43 | { 44 | [super init]; 45 | return self; 46 | } 47 | snippet ifself 48 | if (self = [super init]) { 49 | ${1:/* code */} 50 | } 51 | return self; 52 | snippet ibo 53 | IBOutlet ${1:NSSomeClass} *${2:$1};${3} 54 | # Category 55 | snippet cat 56 | @interface ${1:NSObject} (${2:Category}) 57 | @end 58 | 59 | @implementation $1 ($2) 60 | ${3} 61 | @end 62 | # Category Interface 63 | snippet cath 64 | @interface ${1:NSObject} (${2:Category}) 65 | ${3} 66 | @end 67 | # NSArray 68 | snippet array 69 | NSMutableArray *${1:array} = [NSMutable array];${2} 70 | # NSDictionary 71 | snippet dict 72 | NSMutableDictionary *${1:dict} = [NSMutableDictionary dictionary];${2} 73 | # NSBezierPath 74 | snippet bez 75 | NSBezierPath *${1:path} = [NSBezierPath bezierPath];${2} 76 | # Method 77 | snippet m 78 | - (${1:id})${2:method} 79 | { 80 | ${3} 81 | } 82 | # Method declaration 83 | snippet md 84 | - (${1:id})${2:method};${3} 85 | # IBAction declaration 86 | snippet ibad 87 | - (IBAction)${1:method}:(${2:id})sender;${3} 88 | # IBAction method 89 | snippet iba 90 | - (IBAction)${1:method}:(${2:id})sender 91 | { 92 | ${3} 93 | } 94 | # awakeFromNib method 95 | snippet wake 96 | - (void)awakeFromNib 97 | { 98 | ${1} 99 | } 100 | # Class Method 101 | snippet M 102 | + (${1:id})${2:method} 103 | {${3} 104 | return nil; 105 | } 106 | # Sub-method (Call super) 107 | snippet sm 108 | - (${1:id})${2:method} 109 | { 110 | [super $2];${3} 111 | return self; 112 | } 113 | # Method: Initialize 114 | snippet I 115 | + (void) initialize 116 | { 117 | [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWIthObjectsAndKeys: 118 | ${1}@"value", @"key", 119 | nil]]; 120 | } 121 | # Accessor Methods For: 122 | # Object 123 | snippet objacc 124 | - (${1:id})${2:thing} 125 | { 126 | return $2; 127 | } 128 | 129 | - (void)set$2:($1)${3:new$2} 130 | { 131 | [$3 retain]; 132 | [$2 release]; 133 | $2 = $3; 134 | }${4} 135 | # for (object in array) 136 | snippet forin 137 | for (${1:Class} *${2:some$1} in ${3:array}) { 138 | ${4} 139 | } 140 | snippet forarray 141 | unsigned int ${1:object}Count = [${2:array} count]; 142 | 143 | for (unsigned int index = 0; index < $1Count; index++) { 144 | ${3:id} $1 = [$2 $1AtIndex:index]; 145 | ${4} 146 | } 147 | # IBOutlet 148 | # @property (Objective-C 2.0) 149 | snippet prop 150 | @property (${1:retain}) ${2:NSSomeClass} ${3:*$2};${4} 151 | # @synthesize (Objective-C 2.0) 152 | snippet syn 153 | @synthesize ${1:property};${2} 154 | # [[ alloc] init] 155 | snippet alloc 156 | [[${1:foo} alloc] init${2}];${3} 157 | # retain 158 | snippet ret 159 | [${1:foo} retain];${2} 160 | # release 161 | snippet rel 162 | [${1:foo} release]; 163 | ${2:$1 = nil;} 164 | # autorelease 165 | snippet arel 166 | [${1:foo} autorelease]; 167 | # autorelease pool 168 | snippet pool 169 | NSAutoreleasePool *${1:pool} = [[NSAutoreleasePool alloc] init]; 170 | ${2:/* code */} 171 | [$1 drain]; 172 | # Throw an exception 173 | snippet except 174 | NSException *${1:badness}; 175 | $1 = [NSException exceptionWithName:@"${2:$1Name}" 176 | reason:@"${3}" 177 | userInfo:nil]; 178 | [$1 raise]; 179 | snippet prag 180 | #pragma mark ${1:foo} 181 | snippet cl 182 | @class ${1:Foo};${2} 183 | snippet color 184 | [[NSColor ${1:blackColor}] set]; 185 | -------------------------------------------------------------------------------- /vim/.vim/snippets/php.snippets: -------------------------------------------------------------------------------- 1 | snippet php 2 | 5 | snippet ec 6 | echo "${1:string}"${2}; 7 | snippet inc 8 | include '${1:file}';${2} 9 | snippet inc1 10 | include_once '${1:file}';${2} 11 | snippet req 12 | require '${1:file}';${2} 13 | snippet req1 14 | require_once '${1:file}';${2} 15 | # $GLOBALS['...'] 16 | snippet globals 17 | $GLOBALS['${1:variable}']${2: = }${3:something}${4:;}${5} 18 | snippet $_ COOKIE['...'] 19 | $_COOKIE['${1:variable}']${2} 20 | snippet $_ ENV['...'] 21 | $_ENV['${1:variable}']${2} 22 | snippet $_ FILES['...'] 23 | $_FILES['${1:variable}']${2} 24 | snippet $_ Get['...'] 25 | $_GET['${1:variable}']${2} 26 | snippet $_ POST['...'] 27 | $_POST['${1:variable}']${2} 28 | snippet $_ REQUEST['...'] 29 | $_REQUEST['${1:variable}']${2} 30 | snippet $_ SERVER['...'] 31 | $_SERVER['${1:variable}']${2} 32 | snippet $_ SESSION['...'] 33 | $_SESSION['${1:variable}']${2} 34 | # Start Docblock 35 | snippet /* 36 | /** 37 | * ${1} 38 | **/ 39 | # Class - post doc 40 | snippet doc_cp 41 | /** 42 | * ${1:undocumented class} 43 | * 44 | * @package ${2:default} 45 | * @author ${3:`g:snips_author`} 46 | **/${4} 47 | # Class Variable - post doc 48 | snippet doc_vp 49 | /** 50 | * ${1:undocumented class variable} 51 | * 52 | * @var ${2:string} 53 | **/${3} 54 | # Class Variable 55 | snippet doc_v 56 | /** 57 | * ${3:undocumented class variable} 58 | * 59 | * @var ${4:string} 60 | **/ 61 | ${1:var} $${2};${5} 62 | # Class 63 | snippet doc_c 64 | /** 65 | * ${3:undocumented class} 66 | * 67 | * @packaged ${4:default} 68 | * @author ${5:`g:snips_author`} 69 | **/ 70 | ${1:}class ${2:} 71 | {${6} 72 | } // END $1class $2 73 | # Constant Definition - post doc 74 | snippet doc_dp 75 | /** 76 | * ${1:undocumented constant} 77 | **/${2} 78 | # Constant Definition 79 | snippet doc_d 80 | /** 81 | * ${3:undocumented constant} 82 | **/ 83 | define(${1}, ${2});${4} 84 | # Function - post doc 85 | snippet doc_fp 86 | /** 87 | * ${1:undocumented function} 88 | * 89 | * @return ${2:void} 90 | * @author ${3:`g:snips_author`} 91 | **/${4} 92 | # Function signature 93 | snippet doc_s 94 | /** 95 | * ${4:undocumented function} 96 | * 97 | * @return ${5:void} 98 | * @author ${6:`g:snips_author`} 99 | **/ 100 | ${1}function ${2}(${3});${7} 101 | # Function 102 | snippet doc_f 103 | /** 104 | * ${4:undocumented function} 105 | * 106 | * @return ${5:void} 107 | * @author ${6:`g:snips_author`} 108 | **/ 109 | ${1}function ${2}(${3}) 110 | {${7} 111 | } 112 | # Header 113 | snippet doc_h 114 | /** 115 | * ${1} 116 | * 117 | * @author ${2:`g:snips_author`} 118 | * @version ${3:$Id$} 119 | * @copyright ${4:$2}, `strftime('%d %B, %Y')` 120 | * @package ${5:default} 121 | **/ 122 | 123 | /** 124 | * Define DocBlock 125 | *// 126 | # Interface 127 | snippet doc_i 128 | /** 129 | * ${2:undocumented class} 130 | * 131 | * @package ${3:default} 132 | * @author ${4:`g:snips_author`} 133 | **/ 134 | interface ${1:} 135 | {${5} 136 | } // END interface $1 137 | # class ... 138 | snippet class 139 | /** 140 | * ${1} 141 | **/ 142 | class ${2:ClassName} 143 | { 144 | ${3} 145 | function ${4:__construct}(${5:argument}) 146 | { 147 | ${6:// code...} 148 | } 149 | } 150 | # define(...) 151 | snippet def 152 | define('${1}'${2});${3} 153 | # defined(...) 154 | snippet def? 155 | ${1}defined('${2}')${3} 156 | snippet wh 157 | while (${1:/* condition */}) { 158 | ${2:// code...} 159 | } 160 | # do ... while 161 | snippet do 162 | do { 163 | ${2:// code... } 164 | } while (${1:/* condition */}); 165 | snippet if 166 | if (${1:/* condition */}) { 167 | ${2:// code...} 168 | } 169 | snippet ife 170 | if (${1:/* condition */}) { 171 | ${2:// code...} 172 | } else { 173 | ${3:// code...} 174 | } 175 | ${4} 176 | snippet else 177 | else { 178 | ${1:// code...} 179 | } 180 | snippet elseif 181 | elseif (${1:/* condition */}) { 182 | ${2:// code...} 183 | } 184 | # Tertiary conditional 185 | snippet t 186 | $${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b};${5} 187 | snippet switch 188 | switch ($${1:variable}) { 189 | case '${2:value}': 190 | ${3:// code...} 191 | break; 192 | ${5} 193 | default: 194 | ${4:// code...} 195 | break; 196 | } 197 | snippet case 198 | case '${1:value}': 199 | ${2:// code...} 200 | break;${3} 201 | snippet for 202 | for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) { 203 | ${4: // code...} 204 | } 205 | snippet foreach 206 | foreach ($${1:variable} as $${2:key}) { 207 | ${3:// code...} 208 | } 209 | snippet fun 210 | ${1:public }function ${2:FunctionName}(${3}) 211 | { 212 | ${4:// code...} 213 | } 214 | # $... = array (...) 215 | snippet array 216 | $${1:arrayName} = array('${2}' => ${3});${4} 217 | -------------------------------------------------------------------------------- /script/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Root of dotfiles 4 | SOURCE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.." 5 | 6 | # Include utils 7 | source $SOURCE/script/bash_utils 8 | 9 | TARGET=${1:-~} 10 | if [ ! -d $TARGET ]; then 11 | fail "Invalid target: $TARGET" 12 | exit 1 13 | fi 14 | 15 | TARGET_LITERAL=$TARGET 16 | [[ $TARGET_LITERAL == ~ ]] && TARGET_LITERAL='~' # reduce to '~' 17 | 18 | BACKUP=`mktemp -d /tmp/dotfiles_backup_XXXXXX` 19 | info "Old files will be put in $BACKUP" 20 | 21 | function reuse_or_create_dir { 22 | mkdir "$BACKUP/$1" 23 | if [ ! -e "$TARGET/$1" ]; then 24 | mkdir "$TARGET/$1" 25 | elif [ ! -d "$TARGET/$1" ]; then 26 | mv "$TARGET/$1" "$BACKUP/$1" 27 | mkdir "$TARGET/$1" 28 | fi 29 | } 30 | 31 | reuse_or_create_dir bin 32 | reuse_or_create_dir codes 33 | if [[ $PLATFORM == 'darwin' ]]; then 34 | reuse_or_create_dir bin/darwin 35 | fi 36 | success 'Create bin and codes' 37 | 38 | function link_and_backup { 39 | [ -e "$TARGET/$1" ] && mv "$TARGET/$1" "$BACKUP/$1" 40 | ln -s "$SOURCE/$2" "$TARGET/$1" 41 | } 42 | 43 | link_and_backup .vim vim/.vim 44 | link_and_backup .vimrc vim/.vimrc 45 | link_and_backup .custom_bashrc bash/.bashrc 46 | link_and_backup .tools_aliases bash/.tools_aliases 47 | link_and_backup bin/rename bin/rename 48 | link_and_backup bin/vn bin/vn 49 | if [[ $PLATFORM != 'cygwin' ]]; then 50 | link_and_backup .gitconfig git/.gitconfig 51 | fi 52 | if [[ $PLATFORM == 'cygwin' ]]; then 53 | link_and_backup bin/sudo bin/sudo 54 | link_and_backup bin/pbcopy bin/pbcopy 55 | link_and_backup bin/pbpaste bin/pbpaste 56 | link_and_backup bin/vcvarsall bin/vcvarsall 57 | link_and_backup .minttyrc misc/.minttyrc 58 | fi 59 | success "Link configuration files" 60 | 61 | LASTLINE_OF_BASHRC=$(tail -n 1 "$TARGET/.bashrc" 2>/dev/null) 62 | LASTLINE_TO_BE="source $TARGET_LITERAL/.custom_bashrc" 63 | if [[ ! -e "$TARGET/.bashrc" ]]; then 64 | echo $LASTLINE_TO_BE > "$TARGET/.bashrc" 65 | success "Create $TARGET_LITERAL/.bashrc" 66 | elif [[ $LASTLINE_OF_BASHRC != $LASTLINE_TO_BE ]]; then 67 | echo $LASTLINE_TO_BE >> "$TARGET/.bashrc" 68 | success "Inject $TARGET_LITERAL/.bashrc" 69 | fi 70 | 71 | if [[ $PLATFORM != 'cygwin' ]] && has_command sudo; then 72 | SUDOER_LINE="$USER ALL=(ALL) NOPASSWD: ALL" 73 | if ! sudo grep -q "$SUDOER_LINE" /etc/sudoers; then 74 | sudo cp /etc/sudoers $BACKUP 75 | sudo bash -c 'echo >> /etc/sudoers' 76 | sudo bash -c "echo \"$SUDOER_LINE\" >> /etc/sudoers" 77 | success 'Inject /etc/sudoers' 78 | fi 79 | fi 80 | 81 | if [[ $PLATFORM == 'darwin' ]] && ! has_command brew; then 82 | progress 'Installng Homebrew' 83 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 84 | eval "$(/opt/homebrew/bin/brew shellenv)" 85 | success "Homebrew installed" 86 | brew update 87 | fi 88 | 89 | cd $SOURCE 90 | git submodule sync --quiet 91 | git submodule update --init --quiet --recursive 92 | cd - > /dev/null 93 | 94 | if [[ $PLATFORM == 'darwin' ]]; then 95 | progress 'Installing other useful tools' 96 | has_command tree || cross_install tree 97 | has_command wget || cross_install wget 98 | has_command ohcount || cross_install ohcount 99 | has_command gsed || cross_install gnu-sed 100 | has_command ag || cross_install the_silver_searcher 101 | has_command autojump || cross_install autojump 102 | has_command realpath || cross_install coreutils 103 | has_command cmake || cross_install cmake 104 | has_command ccache || cross_install ccache 105 | success "Tools installed" 106 | elif [[ $PLATFORM == 'linux-gnu' ]]; then 107 | progress 'Installing system tools' 108 | has_command tree || cross_install tree 109 | has_command vim || cross_install vim 110 | has_command ag || cross_install silversearcher-ag 111 | has_command autojump || cross_install autojump 112 | has_command cmake || cross_install cmake 113 | has_command ccache || cross_install ccache 114 | 115 | if [[ $OS == 'Ubuntu' ]]; then 116 | has_command ohcount || cross_install ohcount 117 | has_command g++ || cross_install build-essential 118 | fi 119 | success "Tools installed" 120 | elif [[ $PLATFORM == 'cygwin' ]]; then 121 | bash $SOURCE/script/create_windows_symlinks $TARGET 122 | success 'Create convenient symbol links' 123 | fi 124 | 125 | progress 'Updating node' 126 | if source "$SOURCE/script/update_node"; then 127 | if [[ $NODE_VERSION == $SYSTEM_NODE_VERSION ]]; then 128 | success 'Current node is already latest' 129 | else 130 | success "Node is updated to $NODE_VERSION" 131 | fi 132 | else 133 | fail 'Cannot update node' 134 | fi 135 | 136 | if has_command sudo; then 137 | cp /etc/hosts $BACKUP 138 | bash $SOURCE/script/update_hosts $SOURCE/etc/hosts 139 | success 'Update hosts' 140 | 141 | if [[ $PLATFORM == 'linux-gnu' ]]; then 142 | source "$SOURCE/script/solarize" light 143 | fi 144 | fi 145 | 146 | source "$TARGET/.custom_bashrc" 147 | success 'Load new environment' 148 | 149 | exit 0 150 | -------------------------------------------------------------------------------- /vim/.vim/snippets/html.snippets: -------------------------------------------------------------------------------- 1 | # Some useful Unicode entities 2 | # Non-Breaking Space 3 | snippet nbs 4 |   5 | # ← 6 | snippet left 7 | ← 8 | # → 9 | snippet right 10 | → 11 | # ↑ 12 | snippet up 13 | ↑ 14 | # ↓ 15 | snippet down 16 | ↓ 17 | # ↩ 18 | snippet return 19 | ↩ 20 | # ⇤ 21 | snippet backtab 22 | ⇤ 23 | # ⇥ 24 | snippet tab 25 | ⇥ 26 | # ⇧ 27 | snippet shift 28 | ⇧ 29 | # ⌃ 30 | snippet control 31 | ⌃ 32 | # ⌅ 33 | snippet enter 34 | ⌅ 35 | # ⌘ 36 | snippet command 37 | ⌘ 38 | # ⌥ 39 | snippet option 40 | ⌥ 41 | # ⌦ 42 | snippet delete 43 | ⌦ 44 | # ⌫ 45 | snippet backspace 46 | ⌫ 47 | # ⎋ 48 | snippet escape 49 | ⎋ 50 | # Generic Doctype 51 | snippet doctype HTML 4.01 Strict 52 | 54 | snippet doctype HTML 4.01 Transitional 55 | 57 | snippet doctype HTML 5 58 | 59 | snippet doctype XHTML 1.0 Frameset 60 | 62 | snippet doctype XHTML 1.0 Strict 63 | 65 | snippet doctype XHTML 1.0 Transitional 66 | 68 | snippet doctype XHTML 1.1 69 | 71 | # HTML Doctype 4.01 Strict 72 | snippet docts 73 | 75 | # HTML Doctype 4.01 Transitional 76 | snippet doct 77 | 79 | # HTML Doctype 5 80 | snippet doct5 81 | 82 | # XHTML Doctype 1.0 Frameset 83 | snippet docxf 84 | 86 | # XHTML Doctype 1.0 Strict 87 | snippet docxs 88 | 90 | # XHTML Doctype 1.0 Transitional 91 | snippet docxt 92 | 94 | # XHTML Doctype 1.1 95 | snippet docx 96 | 98 | snippet html 99 | 100 | ${0} 101 | 102 | snippet xhtml 103 | 104 | ${0} 105 | 106 | snippet body 107 | 108 | ${0} 109 | 110 | snippet head 111 | 112 | 113 | ${0:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`} 114 | $1 115 | 116 | snippet title 117 | ${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`}${2} 118 | snippet script 119 | ${2} 122 | snippet scriptsrc 123 | ${2} 124 | snippet style 125 | ${3} 128 | snippet base 129 | 130 | snippet r 131 | 132 | snippet div 133 |
134 | ${2} 135 |
136 | # Embed QT Movie 137 | snippet movie 138 | 140 | 141 | 142 | 143 | 149 | ${6} 150 | snippet fieldset 151 |
152 | ${1:name} 153 | 154 | ${3} 155 |
156 | snippet form 157 |
158 | ${3} 159 | 160 | 161 |

162 |
163 | snippet h1 164 |

${2:$1}

165 | snippet input 166 | ${4} 167 | snippet label 168 | ${7} 169 | snippet link 170 | ${4} 171 | snippet mailto 172 | ${3:email me} 173 | snippet meta 174 | ${3} 175 | snippet opt 176 | ${3} 177 | snippet optt 178 | ${2} 179 | snippet select 180 | ${5} 183 | snippet table 184 | 185 | 186 | 187 |
${2:Header}
${3:Data}
${4} 188 | snippet textarea 189 | ${5} 190 | -------------------------------------------------------------------------------- /vim/.vim/snippets/objcpp.snippets: -------------------------------------------------------------------------------- 1 | # Namespace 2 | snippet ans 3 | namespace { 4 | 5 | ${0} 6 | 7 | } // namespace 8 | snippet fns 9 | namespace ${1:`Filename('', 'my')`} { 10 | ${0} 11 | } 12 | snippet ns 13 | namespace ${1:`Filename('', 'my')`} { 14 | 15 | ${0} 16 | 17 | } // namespace $1 18 | # Class 19 | snippet cl 20 | class ${1:`substitute(Filename('', 'name'), '\(\%(\<\l\+\)\%(_\)\@=\)\|_\(\l\)', '\u\1\2', 'g')`} ${0}{ 21 | public: 22 | $1(); 23 | ~$1() override; 24 | 25 | private: 26 | DISALLOW_COPY_AND_ASSIGN($1); 27 | }; 28 | # #import <...> 29 | snippet Imp 30 | #import <${1:Cocoa/Cocoa.h}>${2} 31 | # #import "..." 32 | snippet imp 33 | #import "${1:`Filename()`.h}"${2} 34 | # @selector(...) 35 | snippet sel 36 | @selector(${1:method}:)${3} 37 | # @"..." string 38 | snippet s 39 | @"${1}"${2} 40 | # Object 41 | snippet o 42 | ${1:NSObject} *${2:foo} = [${3:$1 alloc}]${4};${5} 43 | # NSLog(...) 44 | snippet log 45 | NSLog(@"${1:%@}"${2});${3} 46 | # Class 47 | snippet objc 48 | @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject} 49 | { 50 | } 51 | @end 52 | 53 | @implementation $1 54 | ${3} 55 | @end 56 | # Class Interface 57 | snippet int 58 | @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject} 59 | {${3} 60 | } 61 | ${4} 62 | @end 63 | # Class Implementation 64 | snippet impl 65 | @implementation ${1:`Filename('', 'someClass')`} 66 | ${2} 67 | @end 68 | snippet init 69 | - (id)init 70 | { 71 | [super init]; 72 | return self; 73 | } 74 | snippet ifself 75 | if (self = [super init]) { 76 | ${1:/* code */} 77 | } 78 | return self; 79 | snippet ibo 80 | IBOutlet ${1:NSSomeClass} *${2:$1};${3} 81 | # Category 82 | snippet cat 83 | @interface ${1:NSObject} (${2:Category}) 84 | @end 85 | 86 | @implementation $1 ($2) 87 | ${3} 88 | @end 89 | # Category Interface 90 | snippet cath 91 | @interface ${1:NSObject} (${2:Category}) 92 | ${3} 93 | @end 94 | # NSArray 95 | snippet array 96 | NSMutableArray *${1:array} = [NSMutable array];${2} 97 | # NSDictionary 98 | snippet dict 99 | NSMutableDictionary *${1:dict} = [NSMutableDictionary dictionary];${2} 100 | # NSBezierPath 101 | snippet bez 102 | NSBezierPath *${1:path} = [NSBezierPath bezierPath];${2} 103 | # Method 104 | snippet m 105 | - (${1:id})${2:method} 106 | { 107 | ${3} 108 | } 109 | # Method declaration 110 | snippet md 111 | - (${1:id})${2:method};${3} 112 | # IBAction declaration 113 | snippet ibad 114 | - (IBAction)${1:method}:(${2:id})sender;${3} 115 | # IBAction method 116 | snippet iba 117 | - (IBAction)${1:method}:(${2:id})sender 118 | { 119 | ${3} 120 | } 121 | # awakeFromNib method 122 | snippet wake 123 | - (void)awakeFromNib 124 | { 125 | ${1} 126 | } 127 | # Class Method 128 | snippet M 129 | + (${1:id})${2:method} 130 | {${3} 131 | return nil; 132 | } 133 | # Sub-method (Call super) 134 | snippet sm 135 | - (${1:id})${2:method} 136 | { 137 | [super $2];${3} 138 | return self; 139 | } 140 | # Method: Initialize 141 | snippet I 142 | + (void) initialize 143 | { 144 | [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWIthObjectsAndKeys: 145 | ${1}@"value", @"key", 146 | nil]]; 147 | } 148 | # Accessor Methods For: 149 | # Object 150 | snippet objacc 151 | - (${1:id})${2:thing} 152 | { 153 | return $2; 154 | } 155 | 156 | - (void)set$2:($1)${3:new$2} 157 | { 158 | [$3 retain]; 159 | [$2 release]; 160 | $2 = $3; 161 | }${4} 162 | # for (object in array) 163 | snippet forin 164 | for (${1:Class} *${2:some$1} in ${3:array}) { 165 | ${4} 166 | } 167 | snippet forarray 168 | unsigned int ${1:object}Count = [${2:array} count]; 169 | 170 | for (unsigned int index = 0; index < $1Count; index++) { 171 | ${3:id} $1 = [$2 $1AtIndex:index]; 172 | ${4} 173 | } 174 | # IBOutlet 175 | # @property (Objective-C 2.0) 176 | snippet prop 177 | @property (${1:retain}) ${2:NSSomeClass} ${3:*$2};${4} 178 | # @synthesize (Objective-C 2.0) 179 | snippet syn 180 | @synthesize ${1:property};${2} 181 | # [[ alloc] init] 182 | snippet alloc 183 | [[${1:foo} alloc] init${2}];${3} 184 | # retain 185 | snippet ret 186 | [${1:foo} retain];${2} 187 | # release 188 | snippet rel 189 | [${1:foo} release]; 190 | ${2:$1 = nil;} 191 | # autorelease 192 | snippet arel 193 | [${1:foo} autorelease]; 194 | # autorelease pool 195 | snippet pool 196 | NSAutoreleasePool *${1:pool} = [[NSAutoreleasePool alloc] init]; 197 | ${2:/* code */} 198 | [$1 drain]; 199 | # Throw an exception 200 | snippet except 201 | NSException *${1:badness}; 202 | $1 = [NSException exceptionWithName:@"${2:$1Name}" 203 | reason:@"${3}" 204 | userInfo:nil]; 205 | [$1 raise]; 206 | snippet prag 207 | #pragma mark ${1:foo} 208 | snippet cl 209 | @class ${1:Foo};${2} 210 | snippet color 211 | [[NSColor ${1:blackColor}] set]; 212 | # main() 213 | snippet main 214 | int main(int argc, const char *argv[]) 215 | { 216 | ${0} 217 | return 0; 218 | } 219 | # #include <...> 220 | snippet Inc 221 | #include <${1:stdio.h}>${2} 222 | # #include "..." 223 | snippet inc 224 | #include "${1:`strpart(strpart(expand('%:p'), 0, strridx(expand('%:p'), '.')), strlen(system('git rev-parse --show-toplevel'))).'.h'`}"${2} 225 | # #ifndef ... #define ... #endif 226 | snippet Def 227 | #ifndef $1 228 | #define ${1:SYMBOL} ${2:value} 229 | #endif${3} 230 | snippet def 231 | #define 232 | snippet ifdef 233 | #ifdef ${1:FOO} 234 | ${2:#define } 235 | #endif 236 | snippet #if 237 | #if ${1:FOO} 238 | ${2} 239 | #endif 240 | # Header Include-Guard 241 | # (the randomizer code is taken directly from TextMate; it could probably be 242 | # cleaner, I don't know how to do it in vim script) 243 | snippet once 244 | #ifndef ${1:`toupper(strpart(substitute(expand('%:p'), '/\|\\\|\.', '_', 'g'), strlen(system('git rev-parse --show-toplevel'))).'_')`} 245 | #define $1 246 | 247 | ${0} 248 | 249 | #endif // $1 250 | # If Condition 251 | snippet if 252 | if (${1:/* condition */}) { 253 | ${0:/* code */} 254 | } 255 | snippet el 256 | else { 257 | ${1} 258 | } 259 | # Tertiary conditional 260 | snippet t 261 | ${1:/* condition */} ? ${2:a} : ${3:b} 262 | # Do While Loop 263 | snippet do 264 | do { 265 | ${2:/* code */} 266 | } while (${1:/* condition */}); 267 | # While Loop 268 | snippet wh 269 | while (${1:/* condition */}) { 270 | ${2:/* code */} 271 | } 272 | # For Loop 273 | snippet for 274 | for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) { 275 | ${4:/* code */} 276 | } 277 | # Custom For Loop 278 | snippet forr 279 | for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) { 280 | ${5:/* code */} 281 | } 282 | # Function 283 | snippet fun 284 | ${1:void} ${2:function_name}(${3}) 285 | { 286 | ${4:/* code */} 287 | } 288 | # Function Declaration 289 | snippet fund 290 | ${1:void} ${2:function_name}(${3});${4} 291 | # Typedef 292 | snippet td 293 | typedef ${1:int} ${2:MyCustomType};${3} 294 | # Struct 295 | snippet st 296 | struct ${1:`Filename('$1_t', 'name')`} { 297 | ${2:/* data */} 298 | }${3: /* optional variable list */};${4} 299 | # Typedef struct 300 | snippet tds 301 | typedef struct ${2:_$1 }{ 302 | ${3:/* data */} 303 | } ${1:`Filename('$1_t', 'name')`}; 304 | # Typdef enum 305 | snippet tde 306 | typedef enum { 307 | ${1:/* data */} 308 | } ${2:foo}; 309 | # printf 310 | # unfortunately version this isn't as nice as TextMates's, given the lack of a 311 | # dynamic `...` 312 | snippet pr 313 | printf("${1:%s}\n"${2});${3} 314 | # fprintf (again, this isn't as nice as TextMate's version, but it works) 315 | snippet fpr 316 | fprintf(${1:stderr}, "${2:%s}\n"${3});${4} 317 | snippet . 318 | [${1}]${2} 319 | snippet un 320 | unsigned 321 | -------------------------------------------------------------------------------- /bin/vcvarsall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Source: https://github.com/nathan818fr/vcvars-bash 4 | # Author: Nathan Poirier 5 | # 6 | set -Eeuo pipefail 7 | shopt -s inherit_errexit 8 | 9 | function detect_platform() { 10 | case "${OSTYPE:-}" in 11 | cygwin* | msys* | win32) 12 | declare -gr bash_platform='win_cyg' 13 | ;; 14 | *) 15 | if [[ -n "${WSL_DISTRO_NAME:-}" ]]; then 16 | declare -gr bash_platform='win_wsl' 17 | else 18 | printf 'error: Unsupported platform (%s)\n' "${OSTYPE:-}" >&2 19 | printf 'hint: This script only supports Bash on Windows (Git Bash, WSL, etc.)\n' >&2 20 | return 1 21 | fi 22 | ;; 23 | esac 24 | } 25 | 26 | function detect_mode() { 27 | # Detect the mode depending on the name called 28 | if [[ "$(basename -- "$0")" == vcvarsrun* ]]; then 29 | declare -gr script_mode='run' # vcvarsrun.sh 30 | else 31 | declare -gr script_mode='default' # vcvarsall.sh 32 | fi 33 | } 34 | 35 | function print_usage() { 36 | case "$script_mode" in 37 | default) 38 | cat </dev/null || true; } | fix_crlf | sed '/^Syntax:/d; s/^ vcvarsall.bat //')" 70 | } 71 | 72 | function main() { 73 | detect_platform 74 | detect_mode 75 | 76 | # Parse arguments 77 | if [[ $# -eq 0 ]]; then 78 | print_usage >&2 79 | return 1 80 | fi 81 | 82 | local arg vcvarsall_args=() 83 | for arg in "$@"; do 84 | shift 85 | if [[ "$arg" == '--' ]]; then 86 | if [[ "$script_mode" == 'default' ]]; then 87 | printf 'error: Unexpected argument: --\n' >&2 88 | printf 'hint: Use vcvarsrun to run a command\n' >&2 89 | return 1 90 | fi 91 | break 92 | fi 93 | vcvarsall_args+=("$(cmdesc "$arg")") 94 | done 95 | 96 | if [[ "$script_mode" == 'run' && $# -eq 0 ]]; then 97 | printf 'error: No command specified\n' >&2 98 | return 1 99 | fi 100 | 101 | # Get MSVC environment variables from vcvarsall.bat 102 | local vcvarsall vcvarsall_env 103 | vcvarsall=$(find_vcvarsall) 104 | vcvarsall_env=$({ cmd "$(cmdesc "$vcvarsall")" "${vcvarsall_args[@]}" '&&' 'set' &2 142 | continue 143 | fi 144 | 145 | case "${name^^}" in 146 | LIB | LIBPATH | INCLUDE | EXTERNAL_INCLUDE | COMMANDPROMPTTYPE | DEVENVDIR | EXTENSIONSDKDIR | FRAMEWORK* | \ 147 | PLATFORM | PREFERREDTOOLARCHITECTURE | UCRT* | UNIVERSALCRTSDK* | VCIDE* | VCINSTALL* | VCPKG* | VCTOOLS* | \ 148 | VSCMD* | VSINSTALL* | VS[0-9]* | VISUALSTUDIO* | WINDOWSLIB* | WINDOWSSDK*) 149 | export_env "$name" "$value" 150 | ;; 151 | PATH) 152 | # PATH is a special case, requiring special handling 153 | local new_paths 154 | new_paths=$(pathlist_win_to_unix "$value") # Convert to unix-style path list 155 | new_paths=$(pathlist_normalize "${PATH}:${new_paths}") # Prepend the current PATH 156 | export_env 'WINDOWS_PATH' "$value" 157 | export_env 'PATH' "$new_paths" 158 | ;; 159 | esac 160 | done <<<"$vcvarsall_env" 161 | 162 | if [[ "$initialized" == 'false' ]]; then 163 | printf 'error: vcvarsall.bat failed' >&2 164 | return 1 165 | fi 166 | 167 | # Execute command if needed 168 | if [[ "$script_mode" == 'run' ]]; then 169 | exec "$@" 170 | fi 171 | } 172 | 173 | # Locate vcvarsall.bat 174 | # Inputs: 175 | # VSINSTALLDIR: The path to the Visual Studio installation directory (optional) 176 | # Outputs: 177 | # stdout: The windows-style path to vcvarsall.bat 178 | function find_vcvarsall() { 179 | local vsinstalldir 180 | if [[ -n "${VSINSTALLDIR:-}" ]]; then 181 | vsinstalldir="$VSINSTALLDIR" 182 | else 183 | local vswhere 184 | vswhere=$(command -v 'vswhere' 2>/dev/null || unixpath 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe') 185 | vsinstalldir=$("$vswhere" -latest -property installationPath &2 188 | return 1 189 | fi 190 | fi 191 | 192 | printf '%s\n' "$(winpath "$vsinstalldir")\\VC\\Auxiliary\\Build\\vcvarsall.bat" 193 | } 194 | 195 | # Run a command with cmd.exe 196 | # Inputs: 197 | # $@: The command string to run (use cmdesc to escape arguments when needed) 198 | # Outputs: 199 | # stdout: The cmd.exe standard output 200 | # stderr: The cmd.exe error output 201 | function cmd() { 202 | # This seems to work fine on all supported platforms 203 | # (even with all the weird path and argument conversions on MSYS-like) 204 | MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL='*' cmd.exe /s /c " ; $* " 205 | } 206 | 207 | # Escape a cmd.exe command argument 208 | # Inputs: 209 | # $1: The argument to escape 210 | # Outputs: 211 | # stdout: The escaped argument 212 | function cmdesc() { 213 | # shellcheck disable=SC2001 214 | sed 's/[^0-9A-Za-z]/^\0/g' <<<"$1" 215 | } 216 | 217 | # Convert path to an absolute unix-style path 218 | # Inputs: 219 | # $1: The path to convert 220 | # Outputs: 221 | # stdout: The converted path 222 | function unixpath() { 223 | local path=$1 224 | case "$bash_platform" in 225 | win_wsl) 226 | case "$path" in 227 | [a-zA-Z]:\\* | [a-zA-Z]:/* | \\\\* | //*) 228 | # Convert windows path using wslpath (unix mode, absolute path) 229 | wslpath -u -a -- "$path" 230 | ;; 231 | *) 232 | # Convert unix path using realpath 233 | realpath -m -- "$path" 234 | ;; 235 | esac 236 | ;; 237 | *) 238 | cygpath -u -a -- "$path" 239 | ;; 240 | esac 241 | } 242 | 243 | # Convert path to an absolute windows-style path 244 | # Inputs: 245 | # $1: The path to convert 246 | # Outputs: 247 | # stdout: The converted path 248 | function winpath() { 249 | local path=$1 250 | case "$bash_platform" in 251 | win_wsl) 252 | case "$path" in 253 | [a-zA-Z]:\\* | [a-zA-Z]:/* | \\\\* | //*) 254 | # Already a windows path 255 | printf '%s' "$path" 256 | ;; 257 | *) 258 | # Convert using wslpath (windows mode, absolute path) 259 | wslpath -w -a -- "$path" 260 | ;; 261 | esac 262 | ;; 263 | *) 264 | # Convert using cygpath (windows mode, absolute path, long form) 265 | cygpath -w -a -l -- "$path" 266 | ;; 267 | esac 268 | } 269 | 270 | # Convert a windows-style path list to a unix-style path list 271 | # Inputs: 272 | # $1: The windows-style path list to convert 273 | # Outputs: 274 | # stdout: The converted unix-style path list 275 | function pathlist_win_to_unix() { 276 | local win_paths=$1 277 | 278 | local path_dir first=true 279 | while IFS= read -r -d';' path_dir; do 280 | if [[ -z "$path_dir" ]]; then continue; fi 281 | 282 | if [[ "$first" == 'true' ]]; then first=false; else printf ':'; fi 283 | printf '%s' "$(unixpath "$path_dir")" 284 | done <<<"${win_paths};" 285 | } 286 | 287 | # Normalize a unix-style path list, removing duplicates and empty entries 288 | # Inputs: 289 | # $1: The list to normalize 290 | # Outputs: 291 | # stdout: The normalized path list 292 | function pathlist_normalize() { 293 | local unix_paths=$1 294 | 295 | declare -A seen_paths 296 | local path_dir first=true 297 | while IFS= read -r -d ':' path_dir; do 298 | if [[ -z "$path_dir" ]]; then continue; fi 299 | if [[ -n "${seen_paths[$path_dir]:-}" ]]; then continue; fi 300 | seen_paths[$path_dir]=1 301 | 302 | if [[ "$first" == 'true' ]]; then first=false; else printf ':'; fi 303 | printf '%s' "$path_dir" 304 | done <<<"${unix_paths}:" 305 | } 306 | 307 | # Convert CRLF to LF 308 | # Inputs: 309 | # stdin: The input to convert 310 | # Outputs: 311 | # stdout: The converted input 312 | function fix_crlf() { 313 | sed 's/\r$//' 314 | } 315 | 316 | eval 'main "$@";exit "$?"' 317 | -------------------------------------------------------------------------------- /vim/.vim/snippets/ruby.snippets: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/ruby 2 | snippet #! 3 | #!/usr/bin/ruby 4 | 5 | # New Block 6 | snippet =b 7 | =begin rdoc 8 | ${1} 9 | =end 10 | snippet y 11 | :yields: ${1:arguments} 12 | snippet rb 13 | #!/usr/bin/env ruby -wKU 14 | 15 | snippet req 16 | require "${1}"${2} 17 | snippet # 18 | # => 19 | snippet end 20 | __END__ 21 | snippet case 22 | case ${1:object} 23 | when ${2:condition} 24 | ${3} 25 | end 26 | snippet when 27 | when ${1:condition} 28 | ${2} 29 | snippet def 30 | def ${1:method_name} 31 | ${2} 32 | end 33 | snippet deft 34 | def test_${1:case_name} 35 | ${2} 36 | end 37 | snippet if 38 | if ${1:condition} 39 | ${2} 40 | end 41 | snippet ife 42 | if ${1:condition} 43 | ${2} 44 | else 45 | ${3} 46 | end 47 | snippet elsif 48 | elsif ${1:condition} 49 | ${2} 50 | snippet unless 51 | unless ${1:condition} 52 | ${2} 53 | end 54 | snippet while 55 | while ${1:condition} 56 | ${2} 57 | end 58 | snippet until 59 | until ${1:condition} 60 | ${2} 61 | end 62 | snippet cla class .. end 63 | class ${1:`substitute(Filename(), '^.', '\u&', '')`} 64 | ${2} 65 | end 66 | snippet cla class .. initialize .. end 67 | class ${1:`substitute(Filename(), '^.', '\u&', '')`} 68 | def initialize(${2:args}) 69 | ${3} 70 | end 71 | 72 | 73 | end 74 | snippet cla class .. < ParentClass .. initialize .. end 75 | class ${1:`substitute(Filename(), '^.', '\u&', '')`} < ${2:ParentClass} 76 | def initialize(${3:args}) 77 | ${4} 78 | end 79 | 80 | 81 | end 82 | snippet cla ClassName = Struct .. do .. end 83 | ${1:`substitute(Filename(), '^.', '\u&', '')`} = Struct.new(:${2:attr_names}) do 84 | def ${3:method_name} 85 | ${4} 86 | end 87 | 88 | 89 | end 90 | snippet cla class BlankSlate .. initialize .. end 91 | class ${1:BlankSlate} 92 | instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A__/ } 93 | snippet cla class << self .. end 94 | class << ${1:self} 95 | ${2} 96 | end 97 | # class .. < DelegateClass .. initialize .. end 98 | snippet cla- 99 | class ${1:`substitute(Filename(), '^.', '\u&', '')`} < DelegateClass(${2:ParentClass}) 100 | def initialize(${3:args}) 101 | super(${4:del_obj}) 102 | 103 | ${5} 104 | end 105 | 106 | 107 | end 108 | snippet mod module .. end 109 | module ${1:`substitute(Filename(), '^.', '\u&', '')`} 110 | ${2} 111 | end 112 | snippet mod module .. module_function .. end 113 | module ${1:`substitute(Filename(), '^.', '\u&', '')`} 114 | module_function 115 | 116 | ${2} 117 | end 118 | snippet mod module .. ClassMethods .. end 119 | module ${1:`substitute(Filename(), '^.', '\u&', '')`} 120 | module ClassMethods 121 | ${2} 122 | end 123 | 124 | module InstanceMethods 125 | 126 | end 127 | 128 | def self.included(receiver) 129 | receiver.extend ClassMethods 130 | receiver.send :include, InstanceMethods 131 | end 132 | end 133 | # attr_reader 134 | snippet r 135 | attr_reader :${1:attr_names} 136 | # attr_writer 137 | snippet w 138 | attr_writer :${1:attr_names} 139 | # attr_accessor 140 | snippet rw 141 | attr_accessor :${1:attr_names} 142 | # include Enumerable 143 | snippet Enum 144 | include Enumerable 145 | 146 | def each(&block) 147 | ${1} 148 | end 149 | # include Comparable 150 | snippet Comp 151 | include Comparable 152 | 153 | def <=>(other) 154 | ${1} 155 | end 156 | # extend Forwardable 157 | snippet Forw- 158 | extend Forwardable 159 | # def self 160 | snippet defs 161 | def self.${1:class_method_name} 162 | ${2} 163 | end 164 | # def method_missing 165 | snippet defmm 166 | def method_missing(meth, *args, &blk) 167 | ${1} 168 | end 169 | snippet defd 170 | def_delegator :${1:@del_obj}, :${2:del_meth}, :${3:new_name} 171 | snippet defds 172 | def_delegators :${1:@del_obj}, :${2:del_methods} 173 | snippet am 174 | alias_method :${1:new_name}, :${2:old_name} 175 | snippet app 176 | if __FILE__ == $PROGRAM_NAME 177 | ${1} 178 | end 179 | # usage_if() 180 | snippet usai 181 | if ARGV.${1} 182 | abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${3} 183 | end 184 | # usage_unless() 185 | snippet usau 186 | unless ARGV.${1} 187 | abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${3} 188 | end 189 | snippet array 190 | Array.new(${1:10}) { |${2:i}| ${3} } 191 | snippet hash 192 | Hash.new { |${1:hash}, ${2:key}| $1[$2] = ${3} } 193 | snippet file File.foreach() { |line| .. } 194 | File.foreach(${1:"path/to/file"}) { |${2:line}| ${3} } 195 | snippet file File.read() 196 | File.read(${1:"path/to/file"})${2} 197 | snippet Dir Dir.global() { |file| .. } 198 | Dir.glob(${1:"dir/glob/*"}) { |${2:file}| ${3} } 199 | snippet Dir Dir[".."] 200 | Dir[${1:"glob/**/*.rb"}]${2} 201 | snippet dir 202 | Filename.dirname(__FILE__) 203 | snippet deli 204 | delete_if { |${1:e}| ${2} } 205 | snippet fil 206 | fill(${1:range}) { |${2:i}| ${3} } 207 | # flatten_once() 208 | snippet flao 209 | inject(Array.new) { |${1:arr}, ${2:a}| $1.push(*$2)}${3} 210 | snippet zip 211 | zip(${1:enums}) { |${2:row}| ${3} } 212 | # downto(0) { |n| .. } 213 | snippet dow 214 | downto(${1:0}) { |${2:n}| ${3} } 215 | snippet ste 216 | step(${1:2}) { |${2:n}| ${3} } 217 | snippet tim 218 | times { |${1:n}| ${2} } 219 | snippet upt 220 | upto(${1:1.0/0.0}) { |${2:n}| ${3} } 221 | snippet loo 222 | loop { ${1} } 223 | snippet ea 224 | each { |${1:e}| ${2} } 225 | snippet eab 226 | each_byte { |${1:byte}| ${2} } 227 | snippet eac- each_char { |chr| .. } 228 | each_char { |${1:chr}| ${2} } 229 | snippet eac- each_cons(..) { |group| .. } 230 | each_cons(${1:2}) { |${2:group}| ${3} } 231 | snippet eai 232 | each_index { |${1:i}| ${2} } 233 | snippet eak 234 | each_key { |${1:key}| ${2} } 235 | snippet eal 236 | each_line { |${1:line}| ${2} } 237 | snippet eap 238 | each_pair { |${1:name}, ${2:val}| ${3} } 239 | snippet eas- 240 | each_slice(${1:2}) { |${2:group}| ${3} } 241 | snippet eav 242 | each_value { |${1:val}| ${2} } 243 | snippet eawi 244 | each_with_index { |${1:e}, ${2:i}| ${3} } 245 | snippet reve 246 | reverse_each { |${1:e}| ${2} } 247 | snippet inj 248 | inject(${1:init}) { |${2:mem}, ${3:var}| ${4} } 249 | snippet map 250 | map { |${1:e}| ${2} } 251 | snippet mapwi- 252 | enum_with_index.map { |${1:e}, ${2:i}| ${3} } 253 | snippet sor 254 | sort { |a, b| ${1} } 255 | snippet sorb 256 | sort_by { |${1:e}| ${2} } 257 | snippet ran 258 | sort_by { rand } 259 | snippet all 260 | all? { |${1:e}| ${2} } 261 | snippet any 262 | any? { |${1:e}| ${2} } 263 | snippet cl 264 | classify { |${1:e}| ${2} } 265 | snippet col 266 | collect { |${1:e}| ${2} } 267 | snippet det 268 | detect { |${1:e}| ${2} } 269 | snippet fet 270 | fetch(${1:name}) { |${2:key}| ${3} } 271 | snippet fin 272 | find { |${1:e}| ${2} } 273 | snippet fina 274 | find_all { |${1:e}| ${2} } 275 | snippet gre 276 | grep(${1:/pattern/}) { |${2:match}| ${3} } 277 | snippet sub 278 | ${1:g}sub(${2:/pattern/}) { |${3:match}| ${4} } 279 | snippet sca 280 | scan(${1:/pattern/}) { |${2:match}| ${3} } 281 | snippet max 282 | max { |a, b|, ${1} } 283 | snippet min 284 | min { |a, b|, ${1} } 285 | snippet par 286 | partition { |${1:e}|, ${2} } 287 | snippet rej 288 | reject { |${1:e}|, ${2} } 289 | snippet sel 290 | select { |${1:e}|, ${2} } 291 | snippet lam 292 | lambda { |${1:args}| ${2} } 293 | snippet do 294 | do |${1:variable}| 295 | ${2} 296 | end 297 | snippet : 298 | :${1:key} => ${2:"value"}${3} 299 | snippet ope 300 | open(${1:"path/or/url/or/pipe"}, "${2:w}") { |${3:io}| ${4} } 301 | # path_from_here() 302 | snippet patfh 303 | File.join(File.dirname(__FILE__), *%2[${1:rel path here}])${2} 304 | # unix_filter {} 305 | snippet unif 306 | ARGF.each_line${1} do |${2:line}| 307 | ${3} 308 | end 309 | # option_parse {} 310 | snippet optp 311 | require "optparse" 312 | 313 | options = {${1:default => "args"}} 314 | 315 | ARGV.options do |opts| 316 | opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} 317 | snippet opt 318 | opts.on( "-${1:o}", "--${2:long-option-name}", ${3:String}, 319 | "${4:Option description.}") do |${5:opt}| 320 | ${6} 321 | end 322 | snippet tc 323 | require "test/unit" 324 | 325 | require "${1:library_file_name}" 326 | 327 | class Test${2:$1} < Test::Unit::TestCase 328 | def test_${3:case_name} 329 | ${4} 330 | end 331 | end 332 | snippet ts 333 | require "test/unit" 334 | 335 | require "tc_${1:test_case_file}" 336 | require "tc_${2:test_case_file}"${3} 337 | snippet as 338 | assert(${1:test}, "${2:Failure message.}")${3} 339 | snippet ase 340 | assert_equal(${1:expected}, ${2:actual})${3} 341 | snippet asne 342 | assert_not_equal(${1:unexpected}, ${2:actual})${3} 343 | snippet asid 344 | assert_in_delta(${1:expected_float}, ${2:actual_float}, ${3:2 ** -20})${4} 345 | snippet asio 346 | assert_instance_of(${1:ExpectedClass}, ${2:actual_instance})${3} 347 | snippet asko 348 | assert_kind_of(${1:ExpectedKind}, ${2:actual_instance})${3} 349 | snippet asn 350 | assert_nil(${1:instance})${2} 351 | snippet asnn 352 | assert_not_nil(${1:instance})${2} 353 | snippet asm 354 | assert_match(/${1:expected_pattern}/, ${2:actual_string})${3} 355 | snippet asnm 356 | assert_no_match(/${1:unexpected_pattern}/, ${2:actual_string})${3} 357 | snippet aso 358 | assert_operator(${1:left}, :${2:operator}, ${3:right})${4} 359 | snippet asr 360 | assert_raise(${1:Exception}) { ${2} } 361 | snippet asnr 362 | assert_nothing_raised(${1:Exception}) { ${2} } 363 | snippet asrt 364 | assert_respond_to(${1:object}, :${2:method})${3} 365 | snippet ass assert_same(..) 366 | assert_same(${1:expected}, ${2:actual})${3} 367 | snippet ass assert_send(..) 368 | assert_send([${1:object}, :${2:message}, ${3:args}])${4} 369 | snippet asns 370 | assert_not_same(${1:unexpected}, ${2:actual})${3} 371 | snippet ast 372 | assert_throws(:${1:expected}) { ${2} } 373 | snippet asnt 374 | assert_nothing_thrown { ${1} } 375 | snippet fl 376 | flunk("${1:Failure message.}")${2} 377 | # Benchmark.bmbm do .. end 378 | snippet bm- 379 | TESTS = ${1:10_000} 380 | Benchmark.bmbm do |results| 381 | ${2} 382 | end 383 | snippet rep 384 | results.report("${1:name}:") { TESTS.times { ${2} }} 385 | # Marshal.dump(.., file) 386 | snippet Md 387 | File.open(${1:"path/to/file.dump"}, "wb") { |${2:file}| Marshal.dump(${3:obj}, $2) }${4} 388 | # Mashal.load(obj) 389 | snippet Ml 390 | File.open(${1:"path/to/file.dump"}, "rb") { |${2:file}| Marshal.load($2) }${3} 391 | # deep_copy(..) 392 | snippet deec 393 | Marshal.load(Marshal.dump(${1:obj_to_copy}))${2} 394 | snippet Pn- 395 | PStore.new(${1:"file_name.pstore"})${2} 396 | snippet tra 397 | transaction(${1:true}) { ${2} } 398 | # xmlread(..) 399 | snippet xml- 400 | REXML::Document.new(File.read(${1:"path/to/file"}))${2} 401 | # xpath(..) { .. } 402 | snippet xpa 403 | elements.each(${1:"//Xpath"}) do |${2:node}| 404 | ${3} 405 | end 406 | # class_from_name() 407 | snippet clafn 408 | split("::").inject(Object) { |par, const| par.const_get(const) } 409 | # singleton_class() 410 | snippet sinc 411 | class << self; self end 412 | snippet nam 413 | namespace :${1:`Filename()`} do 414 | ${2} 415 | end 416 | snippet tas 417 | desc "${1:Task description\}" 418 | task :${2:task_name => [:dependent, :tasks]} do 419 | ${3} 420 | end 421 | -------------------------------------------------------------------------------- /vim/.vim/autoload/pathogen.vim: -------------------------------------------------------------------------------- 1 | " pathogen.vim - path option manipulation 2 | " Maintainer: Tim Pope 3 | " Version: 2.2 4 | 5 | " Install in ~/.vim/autoload (or ~\vimfiles\autoload). 6 | " 7 | " For management of individually installed plugins in ~/.vim/bundle (or 8 | " ~\vimfiles\bundle), adding `call pathogen#infect()` to the top of your 9 | " .vimrc is the only other setup necessary. 10 | " 11 | " The API is documented inline below. For maximum ease of reading, 12 | " :set foldmethod=marker 13 | 14 | if exists("g:loaded_pathogen") || &cp 15 | finish 16 | endif 17 | let g:loaded_pathogen = 1 18 | 19 | function! s:warn(msg) 20 | if &verbose 21 | echohl WarningMsg 22 | echomsg a:msg 23 | echohl NONE 24 | endif 25 | endfunction 26 | 27 | " Point of entry for basic default usage. Give a relative path to invoke 28 | " pathogen#incubate() (defaults to "bundle/{}"), or an absolute path to invoke 29 | " pathogen#surround(). For backwards compatibility purposes, a full path that 30 | " does not end in {} or * is given to pathogen#runtime_prepend_subdirectories() 31 | " instead. 32 | function! pathogen#infect(...) abort " {{{1 33 | for path in a:0 ? reverse(copy(a:000)) : ['bundle/{}'] 34 | if path =~# '^[^\\/]\+$' 35 | call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')') 36 | call pathogen#incubate(path . '/{}') 37 | elseif path =~# '^[^\\/]\+[\\/]\%({}\|\*\)$' 38 | call pathogen#incubate(path) 39 | elseif path =~# '[\\/]\%({}\|\*\)$' 40 | call pathogen#surround(path) 41 | else 42 | call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')') 43 | call pathogen#surround(path . '/{}') 44 | endif 45 | endfor 46 | call pathogen#cycle_filetype() 47 | return '' 48 | endfunction " }}}1 49 | 50 | " Split a path into a list. 51 | function! pathogen#split(path) abort " {{{1 52 | if type(a:path) == type([]) | return a:path | endif 53 | let split = split(a:path,'\\\@"),'!isdirectory(v:val)')) && (!filereadable(dir.sep.'doc'.sep.'tags') || filewritable(dir.sep.'doc'.sep.'tags')) 226 | helptags `=dir.'/doc'` 227 | endif 228 | endfor 229 | endfor 230 | endfunction " }}}1 231 | 232 | command! -bar Helptags :call pathogen#helptags() 233 | 234 | " Execute the given command. This is basically a backdoor for --remote-expr. 235 | function! pathogen#execute(...) abort " {{{1 236 | for command in a:000 237 | execute command 238 | endfor 239 | return '' 240 | endfunction " }}}1 241 | 242 | " Like findfile(), but hardcoded to use the runtimepath. 243 | function! pathogen#runtime_findfile(file,count) abort "{{{1 244 | let rtp = pathogen#join(1,pathogen#split(&rtp)) 245 | let file = findfile(a:file,rtp,a:count) 246 | if file ==# '' 247 | return '' 248 | else 249 | return fnamemodify(file,':p') 250 | endif 251 | endfunction " }}}1 252 | 253 | " Backport of fnameescape(). 254 | function! pathogen#fnameescape(string) abort " {{{1 255 | if exists('*fnameescape') 256 | return fnameescape(a:string) 257 | elseif a:string ==# '-' 258 | return '\-' 259 | else 260 | return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','') 261 | endif 262 | endfunction " }}}1 263 | 264 | if exists(':Vedit') 265 | finish 266 | endif 267 | 268 | let s:vopen_warning = 0 269 | 270 | function! s:find(count,cmd,file,lcd) " {{{1 271 | let rtp = pathogen#join(1,pathogen#split(&runtimepath)) 272 | let file = pathogen#runtime_findfile(a:file,a:count) 273 | if file ==# '' 274 | return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'" 275 | endif 276 | if !s:vopen_warning 277 | let s:vopen_warning = 1 278 | let warning = '|echohl WarningMsg|echo "Install scriptease.vim to continue using :V'.a:cmd.'"|echohl NONE' 279 | else 280 | let warning = '' 281 | endif 282 | if a:lcd 283 | let path = file[0:-strlen(a:file)-2] 284 | execute 'lcd `=path`' 285 | return a:cmd.' '.pathogen#fnameescape(a:file) . warning 286 | else 287 | return a:cmd.' '.pathogen#fnameescape(file) . warning 288 | endif 289 | endfunction " }}}1 290 | 291 | function! s:Findcomplete(A,L,P) " {{{1 292 | let sep = pathogen#separator() 293 | let cheats = { 294 | \'a': 'autoload', 295 | \'d': 'doc', 296 | \'f': 'ftplugin', 297 | \'i': 'indent', 298 | \'p': 'plugin', 299 | \'s': 'syntax'} 300 | if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0]) 301 | let request = cheats[a:A[0]].a:A[1:-1] 302 | else 303 | let request = a:A 304 | endif 305 | let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*' 306 | let found = {} 307 | for path in pathogen#split(&runtimepath) 308 | let path = expand(path, ':p') 309 | let matches = split(glob(path.sep.pattern),"\n") 310 | call map(matches,'isdirectory(v:val) ? v:val.sep : v:val') 311 | call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]') 312 | for match in matches 313 | let found[match] = 1 314 | endfor 315 | endfor 316 | return sort(keys(found)) 317 | endfunction " }}}1 318 | 319 | command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(,'edit',,0) 320 | command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(,'edit',,0) 321 | command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(,'edit',,1) 322 | command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(,'split',,1) 323 | command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(,'vsplit',,1) 324 | command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(,'tabedit',,1) 325 | command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(,'pedit',,1) 326 | command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(,'read',,1) 327 | 328 | " vim:set et sw=2: 329 | -------------------------------------------------------------------------------- /bin/rename: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | use strict; 3 | use warnings; 4 | 5 | use Getopt::Long 2.24, qw( :config bundling no_ignore_case no_auto_abbrev ); 6 | 7 | my ( $N, $EXT, @EXT, @USE, $DECODE, $ENCODE ); 8 | sub compile { eval shift } # defined early to control the lexical environment 9 | 10 | my $msglevel = 0; 11 | sub ERROR (&) { print STDERR $_[0]->(), "\n" if $msglevel > -1 }; 12 | sub INFO (&) { print STDERR $_[0]->(), "\n" if $msglevel > 0 }; 13 | sub DEBUG (&) { print STDERR $_[0]->(), "\n" if $msglevel > 1 }; 14 | 15 | sub pod2usage { require Pod::Usage; goto &Pod::Usage::pod2usage } 16 | sub mkpath { require File::Path; goto &File::Path::mkpath } 17 | sub dirname { require File::Basename; goto &File::Basename::dirname } 18 | 19 | use constant VERB_FOR => { 20 | link => { 21 | inf => 'link', 22 | pastp => 'linked', 23 | exec => sub { link shift, shift }, 24 | }, 25 | symlink => { 26 | inf => 'symlink', 27 | pastp => 'symlinked', 28 | exec => sub { symlink shift, shift }, 29 | }, 30 | rename => { 31 | inf => 'rename', 32 | pastp => 'renamed', 33 | exec => sub { rename shift, shift }, 34 | }, 35 | }; 36 | 37 | sub argv_to_subst_expr { 38 | my $modifier = shift || ''; 39 | pod2usage( -verbose => 1 ) if @ARGV < 2; 40 | my ($from, $to) = map quotemeta, splice @ARGV, 0, 2; 41 | # the ugly \${\""} construct is necessary because unknown backslash escapes are 42 | # not treated the same in pattern- vs doublequote-quoting context; only the 43 | # latter lets us do the right thing with problematic input like 44 | # ']{ool(haracter$' or maybe '>>' 45 | sprintf 's/\Q${\"%s"}/%s/%s', $from, $to, $modifier; 46 | } 47 | 48 | sub pipe_through { 49 | my ( $cmd ) = @_; 50 | IPC::Open2::open2( my $in, my $out, $cmd ) or do { 51 | warn "couldn't open pipe to $cmd: $!\n"; 52 | return; 53 | }; 54 | print $out $_; 55 | close $out; 56 | $_ = <$in>; 57 | chomp; 58 | close $in; 59 | } 60 | 61 | my ( $VERB, @EXPR ); 62 | 63 | my %library = ( 64 | camelcase => 's/([[:alpha:]]+)/\u$1/g', 65 | urlesc => 's/%([0-9A-F][0-9A-F])/chr hex $1/ieg', 66 | nows => 's/[_[:blank:]]+/_/g', 67 | rews => 'y/_/ /', 68 | noctrl => 's/[_[:cntrl:]]+/_/g', 69 | nometa => 'tr/_!"&()=?`*\':;<>|$/_/s', 70 | trim => 's/\A[ _]+//, s/[ _]+\z//' 71 | ); 72 | 73 | GetOptions( 74 | 'h|help' => sub { pod2usage() }, 75 | 'man' => sub { pod2usage( -verbose => 2 ) }, 76 | '0|null' => \my $opt_null, 77 | 'f|force' => \my $opt_force, 78 | 'g|glob' => \my $opt_glob, 79 | 'i|interactive' => \my $opt_interactive, 80 | 'k|backwards|reverse-order' => \my $opt_backwards, 81 | 'l|symlink' => sub { $VERB ? pod2usage( -verbose => 1 ) : ( $VERB = VERB_FOR->{ 'symlink' } ) }, 82 | 'L|hardlink' => sub { $VERB ? pod2usage( -verbose => 1 ) : ( $VERB = VERB_FOR->{ 'link' } ) }, 83 | 'M|use=s' => \@USE, 84 | 'n|just-print|dry-run' => \my $opt_dryrun, 85 | 'N|counter-format=s' => \my $opt_ntmpl, 86 | 'p|mkpath|make-dirs' => \my $opt_mkpath, 87 | 'stdin!' => \my $opt_stdin, 88 | 't|sort-time' => \my $opt_time_sort, 89 | 'T|transcode=s' => \my $opt_transcode, 90 | 'v|verbose+' => \$msglevel, 91 | 92 | 'a|append=s' => sub { push @EXPR, "\$_ .= qq[${\quotemeta $_[1]}]" }, 93 | 'A|prepend=s' => sub { push @EXPR, "substr \$_, 0, 0, qq[${\quotemeta $_[1]}]" }, 94 | 'c|lower-case' => sub { push @EXPR, 's/([[:upper:]]+)/\L$1/g' }, 95 | 'C|upper-case' => sub { push @EXPR, 's/([[:lower:]]+)/\U$1/g' }, 96 | 'd|delete=s' => sub { push @EXPR, "s/${\quotemeta $_[1]}//" }, 97 | 'D|delete-all=s' => sub { push @EXPR, "s/${\quotemeta $_[1]}//g" }, 98 | 'e|expr=s' => \@EXPR, 99 | 'P|pipe=s' => sub { require IPC::Open2; push @EXPR, "pipe_through '\Q$_[1]\E'" }, 100 | 's|subst' => sub { push @EXPR, argv_to_subst_expr }, 101 | 'S|subst-all' => sub { push @EXPR, argv_to_subst_expr('g') }, 102 | 'x|remove-extension' => sub { push @EXPR, 's/\. [^.]+ \z//x' }, 103 | 'X|keep-extension' => sub { push @EXPR, 's/\.([^.]+)\z//x and do { push @EXT, $1; $EXT = join ".", reverse @EXT }' }, 104 | 'z|sanitize' => sub { push @EXPR, @library{ qw( nows noctrl nometa trim ) } }, 105 | 106 | map { my $recipe = $_; $recipe => sub { push @EXPR, $library{ $recipe } } } keys %library, 107 | ) or pod2usage(); 108 | 109 | $opt_stdin = @ARGV ? 0 : 1 unless defined $opt_stdin; 110 | 111 | $VERB ||= VERB_FOR->{ 'rename' }; 112 | 113 | if ( not @EXPR ) { 114 | pod2usage() if not @ARGV or -e $ARGV[0]; 115 | push @EXPR, shift; 116 | } 117 | 118 | pod2usage( -message => 'Error: --stdin and filename arguments are mutually exclusive' ) 119 | if $opt_stdin and @ARGV; 120 | 121 | pod2usage( -message => 'Error: --null only permitted when reading filenames from STDIN' ) 122 | if $opt_null and not $opt_stdin; 123 | 124 | pod2usage( -message => 'Error: --interactive and --force are mutually exclusive' ) 125 | if $opt_interactive and $opt_force; 126 | 127 | my $n = 1; 128 | my $nwidth = 0; 129 | if ( defined $opt_ntmpl ) { 130 | $opt_ntmpl =~ /\A(?:(\.\.\.0)|(0+))([0-9]+)\z/ 131 | or pod2usage( -message => "Error: unparseable counter format $opt_ntmpl" ); 132 | $nwidth = ( 133 | defined $1 ? -1 : 134 | defined $2 ? length $opt_ntmpl : 135 | 0 136 | ); 137 | $n = $3; 138 | } 139 | 140 | ++$msglevel if $opt_dryrun; 141 | 142 | my $code = do { 143 | if ( $opt_transcode ) { 144 | require Encode; 145 | my ( $in_enc, $out_enc ) = split /:/, $opt_transcode, 2; 146 | $DECODE = Encode::find_encoding( $in_enc ); 147 | die "No such encoding $in_enc\n" if not ref $DECODE; 148 | $ENCODE = defined $out_enc ? Encode::find_encoding( $out_enc ) : $ENCODE; 149 | die "No such encoding $out_enc\n" if not ref $ENCODE; 150 | unshift @EXPR, '$_ = $DECODE->decode($_)'; 151 | push @EXPR, '$_ = $ENCODE->encode($_)'; 152 | } 153 | 154 | my $i = $#USE; 155 | for ( reverse @USE ) { 156 | s/\A([^=]+)=?//; 157 | my $use = "use $1"; 158 | $use .= ' split /,/, $USE['.$i--.']' if length; 159 | unshift @EXPR, $use; 160 | } 161 | 162 | if ( eval 'require feature' and $^V =~ /^v(5\.[1-9][0-9]+)/ ) { 163 | unshift @EXPR, "use feature ':$1'"; 164 | } 165 | 166 | my $cat = sprintf 'sub { %s }', join '; ', @EXPR; 167 | DEBUG { "Using expression: $cat" }; 168 | 169 | my $evaled = compile $cat; 170 | die $@ if $@; 171 | die "Evaluation to subref failed. Check expression using -nv\n" 172 | unless 'CODE' eq ref $evaled; 173 | 174 | $evaled; 175 | }; 176 | 177 | if ( $opt_stdin ) { 178 | local $/ = $/; 179 | INFO { "Reading filenames from STDIN" }; 180 | @ARGV = do { 181 | if ( $opt_null ) { 182 | INFO { "Splitting on NUL bytes" }; 183 | $/ = chr 0; 184 | } 185 | ; 186 | }; 187 | chomp @ARGV; 188 | } 189 | 190 | @ARGV = map glob, @ARGV if $opt_glob; 191 | 192 | if ( $opt_time_sort ) { 193 | my @mtime = map { (stat)[9] } @ARGV; 194 | @ARGV = @ARGV[ sort { $mtime[$a] <=> $mtime[$b] } 0 .. $#ARGV ]; 195 | } 196 | 197 | @ARGV = reverse @ARGV if $opt_backwards; 198 | 199 | $nwidth = length $n+@ARGV if $nwidth < 0; 200 | 201 | for ( @ARGV ) { 202 | my $old = $_; 203 | 204 | $N = sprintf '%0*d', $nwidth, $n++; 205 | $code->(); 206 | $_ = join '.', $_, reverse splice @EXT if @EXT; 207 | 208 | if ( $old eq $_ ) { 209 | DEBUG { "'$old' unchanged" }; 210 | next; 211 | } 212 | 213 | if ( !$opt_force and -e ) { 214 | ERROR { "'$old' not $VERB->{pastp}: '$_' already exists" }; 215 | next; 216 | } 217 | 218 | if ( $opt_dryrun ) { 219 | INFO { "'$old' would be $VERB->{pastp} to '$_'" }; 220 | next; 221 | } 222 | 223 | if ( $opt_interactive ) { 224 | print "\u$VERB->{inf} '$old' to '$_'? [n] "; 225 | if ( !~ /^y(?:es)?$/i ) { 226 | DEBUG { "Skipping '$old'." }; 227 | next; 228 | } 229 | } 230 | 231 | my ( $success, @made_dirs ); 232 | 233 | ++$success if $VERB->{ 'exec' }->( $old, $_ ); 234 | 235 | if ( !$success and $opt_mkpath ) { 236 | @made_dirs = mkpath( [ dirname( $_ ) ], $msglevel > 1, 0755 ); 237 | ++$success if $VERB->{ 'exec' }->( $old, $_ ); 238 | } 239 | 240 | if ( !$success ) { 241 | ERROR { "Can't $VERB->{inf} '$old' to '$_': $!" }; 242 | rmdir $_ for reverse @made_dirs; 243 | next; 244 | } 245 | 246 | INFO { "'$old' $VERB->{pastp} to '$_'" }; 247 | } 248 | 249 | __END__ 250 | 251 | =head1 NAME 252 | 253 | rename - renames multiple files 254 | 255 | =head1 VERSION 256 | 257 | version 1.500 258 | 259 | =head1 SYNOPSIS 260 | 261 | F 262 | B<[switches|transforms]> 263 | B<[files]> 264 | 265 | Switches: 266 | 267 | =over 1 268 | 269 | =item B<-0>/B<--null> (when reading from STDIN) 270 | 271 | =item B<-f>/B<--force>EorEB<-i>/B<--interactive> (proceed or prompt when overwriting) 272 | 273 | =item B<-g>/B<--glob> (expand C<*> etc. in filenames, useful in WindowsE F) 274 | 275 | =item B<-k>/B<--backwards>/B<--reverse-order> 276 | 277 | =item B<-l>/B<--symlink>EorEB<-L>/B<--hardlink> 278 | 279 | =item B<-M>/B<--use=I> 280 | 281 | =item B<-n>/B<--just-print>/B<--dry-run> 282 | 283 | =item B<-N>/B<--counter-format> 284 | 285 | =item B<-p>/B<--mkpath>/B<--make-dirs> 286 | 287 | =item B<--stdin>/B<--no-stdin> 288 | 289 | =item B<-t>/B<--sort-time> 290 | 291 | =item B<-T>/B<--transcode=I> 292 | 293 | =item B<-v>/B<--verbose> 294 | 295 | =back 296 | 297 | Transforms, applied sequentially: 298 | 299 | =over 1 300 | 301 | =item B<-a>/B<--append=I> 302 | 303 | =item B<-A>/B<--prepend=I> 304 | 305 | =item B<-c>/B<--lower-case> 306 | 307 | =item B<-C>/B<--upper-case> 308 | 309 | =item B<-d>/B<--delete=I> 310 | 311 | =item B<-D>/B<--delete-all=I> 312 | 313 | =item B<-e>/B<--expr=I> 314 | 315 | =item B<-P>/B<--pipe=I> 316 | 317 | =item B<-s>/B<--subst I I> 318 | 319 | =item B<-S>/B<--subst-all I I> 320 | 321 | =item B<-x>/B<--remove-extension> 322 | 323 | =item B<-X>/B<--keep-extension> 324 | 325 | =item B<-z>/B<--sanitize> 326 | 327 | =item B<--camelcase>EB<--urlesc>EB<--nows>EB<--rews>EB<--noctrl>EB<--nometa>EB<--trim> (see manual) 328 | 329 | =back 330 | 331 | =head1 DESCRIPTION 332 | 333 | This program renames files according to modification rules specified on the command line. If no filenames are given on the command line, a list of filenames will be expected on standard input. 334 | 335 | The documentation contains a L. 336 | 337 | =head1 OPTIONS 338 | 339 | =head2 Switches 340 | 341 | =over 4 342 | 343 | =item B<-h>, B<--help> 344 | 345 | See a synopsis. 346 | 347 | =item B<--man> 348 | 349 | Browse the manpage. 350 | 351 | =item B<-0>, B<--null> 352 | 353 | When reading file names from C, split on NUL bytes instead of newlines. This is useful in combination with GNU find's C<-print0> option, GNU grep's C<-Z> option, and GNU sort's C<-z> option, to name just a few. B 354 | 355 | =item B<-f>, B<--force> 356 | 357 | Rename even when a file with the destination name already exists. 358 | 359 | =item B<-g>, B<--glob> 360 | 361 | Glob filename arguments. This is useful if you're using a braindead shell such as F which won't expand wildcards on behalf of the user. 362 | 363 | =item B<-i>, B<--interactive> 364 | 365 | Ask the user to confirm every action before it is taken. 366 | 367 | =item B<-k>, B<--backwards>, B<--reverse-order> 368 | 369 | Process the list of files in reverse order, last file first. This prevents conflicts when renaming files to names which are currently taken but would be freed later during the process of renaming. 370 | 371 | =item B<-l>, B<--symlink> 372 | 373 | Create symlinks from the new names to the existing ones, instead of renaming the files. B.> 374 | 375 | =item B<-L>, B<--hardlink> 376 | 377 | Create hard links from the new names to the existing ones, instead of renaming the files. B.> 378 | 379 | =item B<-M>, B<--use> 380 | 381 | Like perl's own C<-M> switch. Loads the named modules at the beginning of the rename, and can pass import options separated by commata after an equals sign, i.e. C will pass the C and C import options to C. 382 | 383 | You may load multiple modules by using this option multiple times. 384 | 385 | =item B<-n>, B<--dry-run>, B<--just-print> 386 | 387 | Show how the files would be renamed, but don't actually do anything. 388 | 389 | =item B<-N>/B<--counter-format> 390 | 391 | Format and set the C<$N> counter variable according to the given template. 392 | 393 | E.g. C<-N 001> will make C<$N> start at 1 and be zero-padded to 3 digits, whereas C<-N 0099> will start the counter at 99 and zero-pad it to 4 digits. And so forth. Only digits are allowed in this simple form. 394 | 395 | As a special form, you can prefix the template with C<...0> to indicate that C should determine the width automatically based upon the number of files. E.g. if you pass C<-N ...01> along with 300 files, C<$N> will range from C<001> to C<300>. 396 | 397 | =item B<-p>, B<--mkpath>, B<--make-dirs> 398 | 399 | Create any non-existent directories in the target path. This is very handy if you want to scatter a pile of files into subdirectories based on some part of their name (eg. the first two letters or the extension): you don't need to make all necessary directories beforehand, just tell C to create them as necessary. 400 | 401 | =item B<--stdin>, B<--no-stdin> 402 | 403 | Always E or never E read the list of filenames from STDIN; do not guess based on the presence or absence of filename arguments. B.> 404 | 405 | =item B<-T>, B<--transcode> 406 | 407 | Decode each filename before processing and encode it after processing, according to the given encoding supplied. 408 | 409 | To encode output in a different encoding than input was decoded, supply two encoding names, separated by a colon, e.g. C<-T latin1:utf-8>. 410 | 411 | Only the last C<-T> parameter on the command line is effective. 412 | 413 | =item B<-v>, B<--verbose> 414 | 415 | Print additional information about the operations (not) executed. 416 | 417 | =back 418 | 419 | =head2 Transforms 420 | 421 | Transforms are applied to filenames sequentially. You can use them multiple times; their effects will accrue. 422 | 423 | =over 4 424 | 425 | =item B<-a>, B<--append> 426 | 427 | Append the string argument you supply to every filename. 428 | 429 | =item B<-A>, B<--prepend> 430 | 431 | Prepend the string argument you supply to every filename. 432 | 433 | =item B<-c>, B<--lower-case> 434 | 435 | Convert file names to all lower case. 436 | 437 | =item B<-C>, B<--upper-case> 438 | 439 | Convert file names to all upper case. 440 | 441 | =item B<-e>, B<--expr> 442 | 443 | The C argument to this option should be a Perl expression that assumes the filename in the C<$_> variable and modifies it for the filenames to be renamed. When no other C<-c>, C<-C>, C<-e>, C<-s>, or C<-z> options are given, you can omit the C<-e> from infront of the code. 444 | 445 | =item B<-P>, B<--pipe> 446 | 447 | Pass the filename to an external command on its standard input and read back the transformed filename on its standard output. 448 | 449 | =item B<-s>, B<--subst> 450 | 451 | Perform a simple textual substitution of C to C. The C and C parameters must immediately follow the argument. 452 | 453 | =item B<-S>, B<--subst-all> 454 | 455 | Same as C<-s>, but replaces I instance of the C text by the C text. 456 | 457 | =item B<-x>, B<--remove-extension> 458 | 459 | Remove the last extension from a filename, if there is any. 460 | 461 | =item B<-X>, B<--keep-extension> 462 | 463 | Save and remove the last extension from a filename, if there is any. The saved extension will be appended back to the filename at the end of the rest of the operations. 464 | 465 | Repeating this option will save multiple levels of extension in the right order. 466 | 467 | =item B<-z>, B<--sanitize> 468 | 469 | A shortcut for passing C<--nows --noctrl --nometa --trim>. 470 | 471 | =item B<--camelcase> 472 | 473 | Capitalise every separate word within the filename. 474 | 475 | =item B<--urlesc> 476 | 477 | Decode URL-escaped filenames, such as wget(1) used to produce. 478 | 479 | =item B<--nows> 480 | 481 | Replace all sequences of whitespace in the filename with single underscore characters. 482 | 483 | =item B<--rews> 484 | 485 | Reverse C<--nows>: replace each underscore in the filename with a space. 486 | 487 | =item B<--noctrl> 488 | 489 | Replace all sequences of control characters in the filename with single underscore characters. 490 | 491 | =item B<--nometa> 492 | 493 | Replace every shell meta-character with an underscore. 494 | 495 | =item B<--trim> 496 | 497 | Remove any sequence of spaces and underscores at the left and right ends of the filename. 498 | 499 | =back 500 | 501 | =head1 VARIABLES 502 | 503 | These predefined variables are available for use within any C<-e> expressions you pass. 504 | 505 | =over 4 506 | 507 | =item B<$N> 508 | 509 | A counter that increments for each file in the list. By default, counts up from 1. 510 | 511 | The C<-N> takes a template that specifies the padding and starting value; see L. 512 | 513 | =item B<$EXT> 514 | 515 | A string containing the accumulated extensions saved by C<-X> switches, without a leading dot. See L. 516 | 517 | =item B<@EXT> 518 | 519 | An array containing the accumulated extensions saved by C<-X> switches, from right to left, without any dots. 520 | 521 | The right-most extension is always C<$EXT[0]>, the left-most (if any) is C<$EXT[-1]>. 522 | 523 | =back 524 | 525 | =head1 TUTORIAL 526 | 527 | F takes a list of filenames, runs a list of modification rules against each filename, checks if the result is different from the original filename, and if so, renames the file. The most I way to use it is to pass a line of Perl code as the rule; the most I way is to employ the many switches available to supply rules for common tasks such as stripping extensions. 528 | 529 | For example, to strip the extension from all C<.bak> files, you might use either of these command lines: 530 | 531 | rename -x *.bak 532 | rename 's/\.bak\z//' * 533 | 534 | These do not achive their results in exactly the same way: the former only takes the files that match C<*.bak> in the first place, then strips their last extension; the latter takes all files and strips a C<.bak> from the end of those filenames that have it. As another alternative, if you are confident that none of the filenames has C<.bak> anywhere else than at the end, you might instead choose to write the latter approach using the C<-s> switch: 535 | 536 | rename -s .bak '' * 537 | 538 | Of course you can do multiple changes in one go: 539 | 540 | rename -s .tgz .tar.gz -s .tbz2 .tar.bz2 *.t?z* 541 | 542 | But note that transforms are order sensitive. The following will not do what you probably meant: 543 | 544 | rename -s foo bar -s bar baz * 545 | 546 | Because rules are cumulative, this would first substitute F with F; in the resulting filenames, it would then substitute F with F. So in most cases, it would end up substituting F with F E probably not your intention. So you need to consider the order of rules. 547 | 548 | If you are unsure that your modification rules will do the right thing, try doing a verbose dry run to check what its results would be. A dry run is requested by passing C<-n>: 549 | 550 | rename -n -s bar baz -s foo bar * 551 | 552 | You can combine the various transforms to suit your needs. E.g. files from MicrosoftE WindowsE systems often have blanks and (sometimes nothing but) capital letters in their names. Let's say you have a heap of such files to clean up, I you also want to move them to subdirectories based on extension. The following command will do this for you: 553 | 554 | rename -p -c -z -X -e '$_ = "$EXT/$_" if @EXT' * 555 | 556 | Here, C<-p> tells F to create directories if necessary; C<-c> tells it to lower-case the filename; C<-X> remembers the file extension in the C<$EXT> and C<@EXT> variables; and finally, the C<-e> expression uses those to prepend the extension to the filename as a directory, I there is one. 557 | 558 | That brings us to the secret weapon in F's arsenal: the C<-X> switch. This is a transform that clips the extension off the filename and stows it away at that point during the application of the rules. After all rules are finished, the remembered extension is appended back onto the filename. (You can use multiple C<-X> switches, and they will accumulate multiple extensions as you would expect.) This allows you to do use simple way for doing many things that would get much trickier if you had to make sure to not affect the extension. E.g.: 559 | 560 | rename -X -c --rews --camelcase --nows * 561 | 562 | This will uppercase the first letter of every word in every filename while leaving its extension exactly as before. Or, consider this: 563 | 564 | rename -N ...01 -X -e '$_ = "File-$N"' * 565 | 566 | This will throw away all the existing filenames and simply number the files from 1 through however many files there are E except that it will preserve their extensions. 567 | 568 | Incidentally, note the C<-N> switch and the C<$N> variable used in the Perl expression. See L and L for documentation. 569 | 570 | =head1 COOKBOOK 571 | 572 | Using the C<-M> switch, you can quickly put F to use for just about everything the CPAN offers: 573 | 574 | =head3 Coarsely latinize a directory full of files with non-Latin characters 575 | 576 | rename -T utf8 -MText::Unidecode '$_ = unidecode $_' * 577 | 578 | See L. 579 | 580 | =head3 Sort a directory of pictures into monthwise subdirectories 581 | 582 | rename -p -MImage::EXIF '$_ = "$1-$2/$_" if Image::EXIF->new->file_name($_) 583 | ->get_image_info->{"Image Created"} =~ /(\d\d\d\d):(\d\d)/' *.jpeg 584 | 585 | See L. 586 | 587 | =head1 SEE ALSO 588 | 589 | mv(1), perl(1), find(1), grep(1), sort(1) 590 | 591 | =head1 BUGS 592 | 593 | None currently known. 594 | 595 | =head1 AUTHORS 596 | 597 | Aristotle Pagaltzis 598 | 599 | Idea, inspiration and original code from Larry Wall and Robin Barker. 600 | 601 | =head1 COPYRIGHT 602 | 603 | This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. 604 | --------------------------------------------------------------------------------