-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zsh_functions
71 lines (60 loc) · 1.77 KB
/
.zsh_functions
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
# tar and bzip a directory
function shrinkwrap() {
local dir
readonly dir=$1
if [ -d $dir ]; then
tar -cf ${dir}.tar $dir && bzip2 -9 ${dir}.tar && mv ${dir}.tar.bz2 ${dir}.tbz
else
printf "shrinkwrap: error: yo, I can't shrinkwrap ${dir}\n"
fi
}
function alarm() {
local duration repeat sound_file
readonly duration="${1:=10}"
readonly repeat="${2:=2}"
readonly sound_file="${3:="/usr/share/sounds/speech-dispatcher/canary-long.wav"}"
# Make sure we have aplay.
if [[ -z "$(command -v aplay)" ]]; then
printf "aplay is required to play .wav files\n"
return 1
fi
# Make sure the $sound_file exists.
if [[ ! -e $sound_file ]]; then
printf "${sound_file}: No such file or directory\n"
return 1
fi
sleep $duration
# ALARM!
for r in {1..$repeat}
do
aplay $sound_file 2&>/dev/null
done
}
function venv_info() {
if [ -n "${VIRTUAL_ENV}" ]; then
local name=$(basename $VIRTUAL_ENV)
echo "${ZSH_THEME_VENV_PROMPT_PREFIX}${name}${ZSH_THEME_VENV_PROMPT_SUFFIX}"
fi
}
function jmp() {
local long_url domain shorten_api
readonly long_url=${1}
readonly domain='j.mp'
readonly shorten_api='https://api-ssl.bitly.com/v4/shorten'
if [ -z "${BITLY_TOKEN}" ]; then
echo '$BITLY_TOKEN is unset'; return 1
fi
if [ -z "${long_url}" ]; then
echo 'Usage: jmp long_url'; return 1
fi
curl \
--fail \
--silent \
--request POST \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${BITLY_TOKEN}" \
--data '{"domain": "'${domain}'", "long_url": "'${long_url}'"}' \
$shorten_api |
jq -r '.link' |
sed 's/http:/https:/'
}