├── tools ├── update-bash-profile.sh ├── update-karabiner.sh ├── publish-gh-pages.sh └── update-git-config.sh ├── sample ├── bash-history-config └── git-template │ └── hooks │ └── pre-commit └── base.sh /tools/update-bash-profile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | ___this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | __root_dir="$(dirname $___this_dir)" 6 | 7 | . $__root_dir/base.sh 8 | 9 | bash_profile="$HOME/.bash_profile" 10 | sample_file_name="$__root_dir/sample/bash-history-config" 11 | tag_str="tag_bash_history" 12 | 13 | exe_cmd "copy_from_sample $bash_profile $sample_file_name $tag_str" 14 | -------------------------------------------------------------------------------- /tools/update-karabiner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cli=/Applications/Karabiner.app/Contents/Library/bin/karabiner 4 | 5 | $cli set option.extra_cursor_optionL_kjhl 1 6 | /bin/echo -n . 7 | $cli set remap.controlL2fn 1 8 | /bin/echo -n . 9 | $cli set remap.fn_fkeys_to_consumer_f1 1 10 | /bin/echo -n . 11 | $cli set remap.fn_fkeys_to_consumer_f10 1 12 | /bin/echo -n . 13 | $cli set remap.fn_fkeys_to_consumer_f3_lion 1 14 | /bin/echo -n . 15 | $cli set remap.fn_fkeys_to_consumer_f3_snow 1 16 | /bin/echo -n . 17 | $cli set remap.fn_fkeys_to_consumer_f5 1 18 | /bin/echo -n . 19 | $cli set remap.fn_fkeys_to_consumer_f7 1 20 | /bin/echo -n . 21 | $cli set remap.fn2controlL 1 22 | /bin/echo -n . 23 | /bin/echo 24 | -------------------------------------------------------------------------------- /tools/publish-gh-pages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function exe_cmd() { 4 | echo $1 5 | eval $1 6 | } 7 | 8 | if [ $# -lt 1 ]; then 9 | echo "Usage: sh $0 [ gh-pages | master ]" 10 | exit 11 | fi 12 | 13 | branch=$1 14 | if [ -z "$branch" ] || [ "$branch" != "master" ]; then 15 | branch='gh-pages' 16 | fi 17 | 18 | exe_cmd "jekyll build" 19 | if [ ! -d '_site' ];then 20 | echo "not content to be published" 21 | exit 22 | fi 23 | 24 | exe_cmd "git checkout $branch" 25 | error_code=$? 26 | if [ $error_code != 0 ];then 27 | echo 'Switch branch fail.' 28 | exit 29 | else 30 | ls | grep -v _site CNAME|xargs rm -rf 31 | exe_cmd "cp -r _site/* ." 32 | exe_cmd "rm -rf _site/" 33 | exe_cmd "touch .nojekyll" 34 | fi 35 | -------------------------------------------------------------------------------- /sample/bash-history-config: -------------------------------------------------------------------------------- 1 | 2 | # tag=tag_bash_history 3 | # --------------------- 4 | # http://stackoverflow.com/questions/9457233/unlimited-bash-history 5 | export HISTFILESIZE= 6 | export HISTSIZE=2000 7 | export HISTTIMEFORMAT="[%F %T] " 8 | # Change the file location because certain bash sessions truncate .bash_history file upon close. 9 | # http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login 10 | export HISTFILE=~/.bash_eternal_history 11 | # Force prompt to write history after every command. 12 | # http://superuser.com/questions/20900/bash-history-loss 13 | PROMPT_COMMAND="history -a; $PROMPT_COMMAND" 14 | # Note: every command is written immediately after it's run, so if you accidentally paste a password you cannot just "kill -9 %%" to avoid the history write, you'll need to remove it manually. 15 | -------------------------------------------------------------------------------- /sample/git-template/hooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # A git hook to make sure user.email and user.mail in repository exists before committing 4 | 5 | set -e 6 | 7 | global_email=$(git config --global user.email || true) 8 | global_name=$(git config --global user.name || true) 9 | 10 | repository_email=$(git config user.email || true) 11 | repository_name=$(git config user.name || true) 12 | 13 | if [ -z "$repository_email" ] || [ -z "$repository_name" ] || [ -n "$global_email" ] || [ -n "$global_name" ]; then 14 | # user.email is empty 15 | echo "ERROR: [pre-commit hook] Aborting commit because user.email or user.name is missing. Configure them for this repository. Make sure not to configure globally." 16 | exit 1 17 | fi 18 | 19 | python_file=./git-hooks.py 20 | if [ -f "$python_file" ]; then 21 | python $python_file pre-commit 22 | fi 23 | -------------------------------------------------------------------------------- /tools/update-git-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | my_dir="$(dirname "$0")" 4 | my_dir="$(dirname "$my_dir")" 5 | 6 | . $my_dir/base.sh 7 | 8 | template_dir=$HOME/.git-templates 9 | tempalte_hooks_dir=$template_dir/hooks 10 | exe_cmd "mkdir -p $template_dir" 11 | exe_cmd "cp -rf $my_dir/sample/git-template/hooks $template_dir/" 12 | exe_cmd "chmod -R a+x $tempalte_hooks_dir" 13 | 14 | exe_cmd "git config --global init.templatedir $template_dir" 15 | exe_cmd "git config --global core.fileMode false" 16 | git config --global alias.st 'status' 17 | git config --global alias.ci 'commit' 18 | git config --global alias.sb 'submodule' 19 | git config --global alias.co 'checkout' 20 | git config --global alias.pm 'push origin master' 21 | git config --global alias.pd 'push origin dev' 22 | git config --global alias.lg "log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit" 23 | git config --global alias.d difftool 24 | 25 | git config --global alias.sm 'git branch --set-upstream-to=origin/master master' 26 | 27 | git config --global diff.tool vimdiff 28 | git config --global difftool.prompt false 29 | -------------------------------------------------------------------------------- /base.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | 4 | current_dir=`pwd` 5 | root_dir=$(dirname $current_dir) 6 | 7 | function exe_cmd() 8 | { 9 | echo $1 10 | eval $1 11 | } 12 | 13 | function copy_from_sample() 14 | { 15 | local file_name=$1 16 | local sample_file_name=$2 17 | local tag_after_done=$3 18 | 19 | if [ ! -f $file_name ]; then 20 | exe_cmd "cp -rf $sample_file_name $file_name" 21 | else 22 | local config_content=`cat $sample_file_name` 23 | change_line append $file_name "$tag_after_done" "$config_content"; 24 | fi 25 | } 26 | 27 | # mode file tag_str content 28 | function change_line() 29 | { 30 | local mode=$1 31 | local file=$2 32 | local tag_str=$3 33 | local content=$4 34 | local file_bak=$file".bak" 35 | local file_temp=$file".temp" 36 | cp -f $file $file_bak 37 | if [ $mode == "append" ]; then 38 | grep -q "$tag_str" $file || echo "$content" >> $file 39 | else 40 | cat $file |awk -v mode="$mode" -v tag_str="$tag_str" -v content="$content" ' 41 | { 42 | if ( index($0, tag_str) > 0) { 43 | if ( mode == "after"){ 44 | printf( "%s\n%s\n", $0, content); 45 | 46 | } else if (mode == "before") 47 | { 48 | printf( "%s\n%s\n", content, $0); 49 | 50 | } else if(mode == "replace") 51 | { 52 | print content; 53 | } 54 | } else if ( index ($0, content) > 0) 55 | { 56 | # target content in line 57 | # do nothing 58 | } else 59 | { 60 | print $0; 61 | } 62 | }' > $file_temp 63 | mv $file_temp $file 64 | fi 65 | } 66 | --------------------------------------------------------------------------------