-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions.zsh
executable file
·102 lines (88 loc) · 2.28 KB
/
.functions.zsh
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
#!/bin/zsh
generate_gitignore_global() {
local GITIGNORE_CLONE_DIR="${HOME}/.gitignore"
local GITIGNORE_GLOBAL="${HOME}/.gitignore_global"
local require_update=0
for arg in "$@"; do
if [[ "${arg}" == "-f" ]]; then
require_update=1
fi
done
if [[ ! -d "${GITIGNORE_CLONE_DIR}" ]]; then
git clone --depth 1 https://github.com/github/gitignore.git "${GITIGNORE_CLONE_DIR}"
require_update=1
else
(
cd "${GITIGNORE_CLONE_DIR}" || exit
git checkout --quiet main
git pull origin main 2>/dev/null | grep --quiet 'Already up to date.' &>/dev/null
)
require_update=$?
fi
if [[ -f "${GITIGNORE_GLOBAL}" ]] && [[ "$require_update" -eq 0 ]]; then
echo "Skipped update ${GITIGNORE_GLOBAL}"
return
fi
local ignores=(
Eclipse
JetBrains
MonoDevelop
MicrosoftOffice
VisualStudioCode
macOS
Linux
Windows
)
echo -e '## Code generated by my dotfiles.; DO NOT EDIT.\n' > "${GITIGNORE_GLOBAL}"
for ignore in ${ignores[@]}; do
local IGNORE_PART=$(command cat <<- EOS
########## start ${ignore} ##########
$(command cat "${GITIGNORE_CLONE_DIR}/Global/${ignore}.gitignore")
########## end ${ignore} ##########
EOS
)
echo -e "${IGNORE_PART}\n" >> "${GITIGNORE_GLOBAL}"
done
echo "Updated ${GITIGNORE_GLOBAL}"
}
fzf_npm_scripts() {
if [ ! -e package.json ]; then
echo 'fzf_npm_scripts'
echo 'There is no package.json'
zle send-break
return 1
fi
if ! type jq > /dev/null; then
echo 'fzf_npm_scripts'
echo 'jq command is required'
zle send-break
return 1
fi
local scripts=`jq -r '.scripts | to_entries | .[] | .key + " = " + .value' package.json 2>/dev/null || echo ''`
if [[ -z $scripts ]]; then
echo 'fzf_npm_scripts'
echo 'There is no scripts in package.json'
zle send-break
return 1
fi
local selected=`echo $scripts | FZF_DEFAULT_OPTS='' fzf --height=75% --reverse --exit-0 | awk -F ' = ' '{ print $1}'`
zle reset-prompt
if [[ -z $selected ]]; then
return 0
fi
BUFFER="npm run $selected"
zle accept-line
}
zle -N fzf_npm_scripts
bindkey "^Xn" fzf_npm_scripts
wttr() {
local location="${1// /+}"
shift 2>/dev/null
local args=""
for p in "$@"; do
args+=" --data-urlencode $p "
done
curl -fsSL -H "Accept-Language: ${LANG%_*}" $args --compressed "wttr.in/${location}"
}
autoload -Uz generate_gitignore_global
autoload -Uz wttr