-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.func
More file actions
127 lines (111 loc) · 2.79 KB
/
Copy path.func
File metadata and controls
127 lines (111 loc) · 2.79 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# 第1引数の数が第2引数未満だったら1を返す
# ex) `check_arg $# 0
local check_arg() {
if [[ ${1} -lt ${2} ]]; then
echo "Error: few arguments; expected ${1}" 1>&2
return 1
fi
}
upd() {
echo -e "\e[1;7;32m\`yay -Syu\`\e[m"
yay -Syu --noconfirm --sudoloop
echo -e "\e[1;7;32m\`rustup update\`\e[m"
rustup update
echo -e "\e[1;7;32m\`zinit update\`\e[m"
zinit update --all --no-pager
}
# update screen config by fzf
scr() {
conf_file=$(find ~/.config/hypr/screen -type f | fzf)
if [[ $conf_file != "" ]]; then
echo "source = $conf_file" > ~/.config/hypr/screen.conf
fi
}
histgrep() {
grep -P $@ ~/.histfile | sort | uniq
}
whose() {
yay -Qo $(which $1)
}
comp() {
file_list=""
compile_options=""
exec_args=""
out_name=""
compiler="${CC:-clang}"
for arg_raw in $@; do
if [[ "$arg_raw" == "--" ]]; then
continue
elif [[ "${arg_raw:0:1}" == "-" ]]; then
compile_options+=" $arg_raw"
continue
fi
arg_name=${arg_raw/.*}
arg_ext=${arg_raw/*.}
# Use exact-matched file if it exists (and is c or cpp file)
if [[ -e "${arg_raw}" && "${arg_name}" != "${arg_ext}" && \
( "${arg_ext}" == "c" || "${arg_ext}" == "cpp" ) ]]; then
file_list+=" ${arg_raw}"
if [[ "${arg_ext}" == "cpp" ]]; then
compiler="${CXX:-clang++}"
fi
# priorize "*.c"
elif [[ -e "${arg_name}.c" ]]; then
file_list+=" ${arg_name}.c"
elif [[ -e "${arg_name}.cpp" ]]; then
file_list+=" ${arg_name}.cpp"
compiler="${CXX:-clang++}"
else
echo -e "[\e[0;31mERROR\e[m] Not Found: ${arg_name}.c(pp)?"
return 1
fi
if [[ "${out_name}" == "" ]]; then
out_name=${arg_name}
fi
done
if [[ "${out_name}" == "" ]]; then
echo -e "[\e[0;31mERROR\e[m] Please specify available .c file"
return 1
fi
executable_extension="out"
separator="-----------"
compile="${compiler} -Wall -g ${compile_options} ${CFLAGS} -o ${out_name}.${executable_extension}${file_list}"
run="./${out_name}.${executable_extension} ${exec_args}"
# compile
echo -e "\$ ${compile}"
eval ${compile} || return 1
# run
echo "${separator}"
echo -e "\$ ${run}"
eval ${run}
echo "[Exit: $?]"
echo "${separator}"
}
_comp() {
_arguments '*:source file:_files -g "*.(c|cpp)"'
}
compdef _comp comp
local git_arg() {
check_arg $# 1 || return 1
repo="$1"
if [[ ! "$1" =~ "/" ]]; then
if [[ $# == 1 ]]; then
repo="watasuke102/$repo"
else
repo="$repo/$2"
shift
fi
fi
shift
arg=$@
}
sshclone() {
git_arg $@
echo -e "\e[30;42m>> git clone git@github.com:$repo $arg\e[m"
eval git clone git@github.com:$repo $arg
}
clone() {
git_arg $@
echo -e "\e[30;42m>> git clone https://github.com/$repo $arg\e[m"
eval git clone https://github.com/$repo $arg
}