Skip to content

Commit 55d12b6

Browse files
committed
[add] config/.customfunction, all the custom function will write into there.
1 parent a145074 commit 55d12b6

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

config/.customfunction

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
3+
# for speed up shell
4+
nvm() {
5+
echo "🚨 NVM not loaded! Loading now..."
6+
unset -f nvm
7+
export NVM_PREFIX="$HOME/.nvm"
8+
[ -s "$NVM_PREFIX/nvm.sh" ] && . "$NVM_PREFIX/nvm.sh"
9+
nvm "$@"
10+
}
11+
12+
# extra pipenv command
13+
pipenv_correspond() {
14+
local isDefault=true
15+
local isLS=true
16+
local isRM=false
17+
18+
local show_proj_root=true
19+
local CORRESPOND=""
20+
declare -a venvs_root_arr=()
21+
22+
local help_book='Usage: cat [OPTION]\n\nOPTION:
23+
ls, --list list all the corresponding projects_root & venvs
24+
uls, --useless list all the not existing projects_roots that still have correspondenting venvs
25+
npr, --no-project-root hide projects_root
26+
rm, --remove remove all the venvs from command: "ls" or "uls", deafult is use "uls"
27+
'
28+
function Show_root(){
29+
declare -a venvs_arr=()
30+
declare -i num_venvs=0
31+
if $show_proj_root; then
32+
for f in $(find ~/.local/share/virtualenvs/*/.project -type f); do
33+
proj_root="$(cat $f)" && [ $CORRESPOND -d $proj_root ] && echo "\nproj: $proj_root\nvenv: ${f//\/.project}\n" && venvs_root_arr+=(${f//\/.project}) && num_venvs+=1
34+
done
35+
else
36+
for f in $(find ~/.local/share/virtualenvs/*/.project -type f); do
37+
proj_root="$(cat $f)" && [ $CORRESPOND -d $proj_root ] && echo "${f//\/.project}\n" && venvs_root_arr+=(${f//\/.project}) && num_venvs+=1
38+
done
39+
fi
40+
echo "Total venvs: $num_venvs"
41+
}
42+
if [ "$#" -gt 0 ]; then
43+
while [ "$#" -gt 0 ]; do
44+
case $1 in
45+
"-h" | "--help" )
46+
echo $help_book
47+
return
48+
;;
49+
"ls" | "--list" )
50+
isDefault=false
51+
isLS=true
52+
shift 1
53+
;;
54+
"uls" | "--useless" )
55+
isDefault=false
56+
isLS=false
57+
shift 1
58+
;;
59+
"npr" | "--no-project-root" )
60+
show_proj_root=false
61+
shift 1
62+
;;
63+
"rm" | "--remove" )
64+
isRM=true
65+
shift 1
66+
;;
67+
*)
68+
echo "\e[31mWrong command keyword!\e[0m"
69+
return
70+
;;
71+
esac
72+
done
73+
fi
74+
75+
if ! $isLS || ( $isRM && $isDefault ); then
76+
CORRESPOND="!"
77+
echo "Useless venvs:"
78+
else
79+
echo "Still corresponding venvs:"
80+
fi
81+
82+
Show_root venvs_root_arr
83+
84+
if $isRM; then
85+
while ! $isDefault && $isLS; do
86+
printf "\e[33mAre you sure you want to remove all venvs that still existing projects_roots?[y/n] \e[0m"
87+
read respond
88+
if [ "$respond" = "n" -o "$respond" = "N" ]; then
89+
echo "bye~~~"
90+
return
91+
elif [ "$respond" != "y" -a "$respond" != "Y" ]; then
92+
echo "Must type 'y' or 'n'!"
93+
else
94+
break
95+
fi
96+
done
97+
echo $venvs_root_arr
98+
echo "\e[33mWait...\e[0m"
99+
for value in ${venvs_root_arr[@]}; do
100+
echo "remving... $value"
101+
# rm -rf $value
102+
done
103+
echo "\e[32mSuccessflly removed all venvs!!\e[0m"
104+
fi
105+
}

0 commit comments

Comments
 (0)