-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogressive_enhancement.zsh
107 lines (96 loc) · 2.2 KB
/
progressive_enhancement.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
103
104
105
106
107
# under certain (interactive, basic) conditions, upgrade a command
# to a fancy version
# if I type python with out any arguments, launch ipython instead
python() {
python3 "$@"
}
python3() {
if (($# == 0)); then
echo -e "$(tput setaf 2)Launching ipython instead...$(tput sgr0)"
ipython
else
command python3 "$@"
fi
}
man() {
if [[ -z "$1" ]]; then
macho
else
command man "$@"
fi
}
# https://github.com/odeke-em/drive
# if I run drive outside my google drive
# move to ~/GoogleDrive/
drive() {
local defaultdrive="${HOME}/GoogleDrive"
# early exit if drive doesnt exist where I expect
[[ ! -r "${defaultdrive}" ]] && command drive "$@"
# if not trying to create another google drive instance
if [[ "$1" != 'init' ]]; then
if ! grep -q "${defaultdrive}" <<<"${PWD}"; then
cd "${defaultdrive}" || {
printf "Couldnt change directory to %s\n" "${defaultdrive}"
}
fi
fi
command drive "$@"
}
# https://github.com/charmbracelet/glow
glow() {
# if passed with no arguments
# and theres only one .md file in this
# directory, automatically use it
if (($# == 0)); then
local -a MD_FILES
MD_FILES=()
while IFS= read -r file; do
MD_FILES+=("$file")
done < <(find . -maxdepth 1 -name '*.md')
if [[ "${#MD_FILES[@]}" == "1" ]]; then
command glow "${MD_FILES[*]}"
else
command glow "$@"
fi
else
command glow "$@"
fi
}
alias icat='kitty +kitten icat'
# https://github.com/sharkdp/bat
# https://github.com/ogham/exa
# https://sw.kovidgoyal.net/kitty/kittens/icat/
#
# if trying to 'cat' all images -- use kitty to print the image directly in the terminal
# if only one argument and a directory, ls instead
# else, use bat
cat() {
local all_images=1
local all_dirs=1
if [[ -z "$1" ]]; then
all_images=0
all_dirs=0
else
# loop through arguments
# if its not an image, break -- and use bat instead
# if I'm in tmux -- kitty cant print images, so fallback
for arg in "$@"; do
[[ -z "$TMUX" && -f "$arg" && "$(file-mime "$1")" =~ '^image/' ]] && continue
all_images=0
break
done
for arg in "$@"; do
if [[ ! -d "$arg" ]]; then
all_dirs=0
break
fi
done
fi
if ((all_dirs)); then
exa "$@"
elif ((all_images)); then
icat "$@"
else
bat "$@"
fi
}