-
Notifications
You must be signed in to change notification settings - Fork 13
/
zsh-exa.plugin.zsh
executable file
·124 lines (104 loc) · 3.68 KB
/
zsh-exa.plugin.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env zsh
#####################
# COMMONS
#####################
autoload colors is-at-least
#########################
# CONSTANT
#########################
BOLD="bold"
NONE="NONE"
#########################
# PLUGIN MAIN
#########################
[[ -z "$EXA_HOME" ]] && export EXA_HOME="$HOME/.exa"
ZSH_EXA_VERSION_FILE=${EXA_HOME}/version.txt
#########################
# Functions
#########################
_zsh_exa_log() {
local font=$1
local color=$2
local msg=$3
if [ $font = $BOLD ]
then
echo $fg_bold[$color] "[zsh-exa-plugin] $msg" $reset_color
else
echo $fg[$color] "[zsh-exa-plugin] $msg" $reset_color
fi
}
_zsh_exa_last_version() {
echo $(curl -s https://github.com/gitapi/repos/ogham/exa/releases/latest | grep tag_name | cut -d '"' -f 4)
}
_zsh_exa_download_install() {
local version=$1
local machine
case "$(uname -m)" in
x86_64)
machine=x86_64
# if on Darwin, set $OSTYPE to match the exa release
[[ "$OSTYPE" == "darwin"* ]] && local OSTYPE=macos
;;
*)
_zsh_exa_log $BOLD "red" "Machine $(uname -m) not supported by this plugin"
return 1
;;
esac
_zsh_exa_log $NONE "blue" " -> download and install exa ${version}"
curl -o "${EXA_HOME}/exa.zip" -fsSL https://github.com/ogham/exa/releases/download/${version}/exa-${OSTYPE%-*}-${machine}-${version}.zip || (_zsh_exa_log $BOLD "red" "Error while downloading exa release" ; return)
unzip -o ${EXA_HOME}/exa.zip -d ${EXA_HOME} 2>&1 > /dev/null
rm -rf ${EXA_HOME}/exa.zip
echo ${version} > ${ZSH_EXA_VERSION_FILE}
_zsh_exa_log $BOLD "green" "Install OK"
}
_zsh_exa_install() {
_zsh_exa_log $NONE "blue" "#############################################"
_zsh_exa_log $BOLD "blue" "Installing exa..."
_zsh_exa_log $NONE "blue" "-> creating exa home dir : ${EXA_HOME}"
mkdir -p ${EXA_HOME} || _zsh_exa_log $NONE "green" "dir already exist"
local last_version=$(_zsh_exa_last_version)
_zsh_exa_log $NONE "blue" "-> retrieve last version of exa..."
_zsh_exa_download_install ${last_version}
_zsh_exa_log $NONE "blue" "#############################################"
}
update_zsh_exa() {
_zsh_exa_log $NONE "blue" "#############################################"
_zsh_exa_log $BOLD "blue" "Checking new version of exa..."
local current_version=$(cat ${ZSH_EXA_VERSION_FILE})
local last_version=$(_zsh_exa_last_version)
if is-at-least ${last_version#v*} ${current_version#v*}
then
_zsh_exa_log $BOLD "green" "Already up to date, current version : ${current_version}"
else
_zsh_exa_log $NONE "blue" "-> Updating exa..."
_zsh_exa_download_install ${last_version}
_zsh_exa_log $BOLD "green" "Update OK"
fi
_zsh_exa_log $NONE "blue" "#############################################"
}
_zsh_exa_load() {
# export PATH if needed
local -r plugin_dir=${EXA_HOME}/bin
# Add the plugin bin directory path if it doesn't exist in $PATH.
if [[ -z ${path[(r)$plugin_dir]} ]]; then
path+=($plugin_dir)
fi
}
# install exa if it isnt already installed
[[ ! -f "${ZSH_EXA_VERSION_FILE}" ]] && _zsh_exa_install
# load exa if it is installed
if [[ -f "${ZSH_EXA_VERSION_FILE}" ]]; then
_zsh_exa_load
fi
########################################################
##### ALIASES
########################################################
alias ll='exa -lbF --git'
alias la='exa -lbhHigmuSa --time-style=long-iso --git --color-scale'
alias lx='exa -lbhHigmuSa@ --time-style=long-iso --git --color-scale'
alias llt='exa -l --git --tree'
alias lt='exa --tree --level=2'
## Sorts
alias llm='exa -lbGF --git --sort=modified'
alias lld='exa -lbhHFGmuSa --group-directories-first'
unset -f _zsh_exa_install _zsh_exa_load