forked from ZengjfOS/anpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom.sh
82 lines (75 loc) · 2.34 KB
/
custom.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 1. argv: refer to config.json "project_keys" array order except ${1}
# ${1}: cmd
# ${2}: defaultPath
# ${3}: project
# ${4}: product
# ${5}: kernel
# ${6}: dts
# ${7}: bootloaderStage1
# ${8}: bootloaderStage2
# ${9}: out
# ${10}: efuse
# 2. return:
# 0: function run success
function project_product_custom() {
# echo "argc: $#"
# echo "argv: $@"
if [ $1 == "test" ]; then
return 0
elif [ $# -eq 1 ] && [ $1 == "vim" ]; then
touch ~/.vimrc
vim_anpp_config_start=`grep "ANPP CONFIG START" ~/.vimrc`
vim_anpp_config_end=`grep "ANPP CONFIG END" ~/.vimrc`
if [ -z "${vim_anpp_config_start}" ] && [ -z "${vim_anpp_config_end}" ]; then
cat <<EOF >> ~/.vimrc
" ANPP CONFIG START
filetype on
filetype plugin on
filetype indent on
syntax enable
set hlsearch
hi Search cterm=NONE ctermfg=white ctermbg=black
set tabstop=4
set shiftwidth=4
" ANPP CONFIG END
EOF
else
# 1. Using sed to delete all lines between two matching patterns
# https://stackoverflow.com/questions/6287755/using-sed-to-delete-all-lines-between-two-matching-patterns
sed -i '/" ANPP CONFIG START/,/" ANPP CONFIG END/{{d;};}' ~/.vimrc
fi
return 0
elif [ $# -eq 1 ] && [ $1 == "tmux" ]; then
touch ~/.tmux.conf
tmux_anpp_config_start=`grep "ANPP CONFIG START" ~/.tmux.conf`
tmux_anpp_config_end=`grep "ANPP CONFIG END" ~/.tmux.conf`
if [ -z "${tmux_anpp_config_start}" ] && [ -z "${tmux_anpp_config_end}" ]; then
cat <<EOF >> ~/.tmux.conf
# ANPP CONFIG START
set -g default-terminal "screen-256color"
set -g history-limit 10000
# Use Alt-arrow keys to switch panes
unbind-key j
bind-key j select-pane -D
unbind-key k
bind-key k select-pane -U
unbind-key h
bind-key h select-pane -L
unbind-key l
bind-key l select-pane -R
unbind '"'
bind - splitw -v -c '#{pane_current_path}'
unbind %
bind | splitw -h -c '#{pane_current_path}'
# ANPP CONFIG END
EOF
else
# 1. Using sed to delete all lines between two matching patterns
# https://stackoverflow.com/questions/6287755/using-sed-to-delete-all-lines-between-two-matching-patterns
sed -i '/# ANPP CONFIG START/,/# ANPP CONFIG END/{{d;};}' ~/.tmux.conf
fi
return 0
else
return 1
fi
}