-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_nnn.sh
80 lines (63 loc) · 2.99 KB
/
setup_nnn.sh
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
#!/bin/bash
# check ubuntu version
release_ver="$(lsb_release -rs)"
# add the relevant repo
if [[ $(echo "$release_ver >= 22.04" | bc) == 1 ]]; then
echo 'deb http://download.opensuse.org/repositories/home:/stig124:/nnn/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/nnn.list
curl -fsSL https://download.opensuse.org/repositories/home:stig124:nnn/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_stig124_nnn.gpg >/dev/null
elif [[ $(echo "$release_ver >= 20.04 && $release_ver < 22.04" | bc) == 1 ]]; then
echo 'deb http://download.opensuse.org/repositories/home:/stig124:/nnn/xUbuntu_20.04/ /' | sudo tee /etc/apt/sources.list.d/nnn.list
curl -fsSL https://download.opensuse.org/repositories/home:stig124:nnn/xUbuntu_20.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_stig124_nnn.gpg >/dev/null
elif [[ $(echo "$release_ver >= 18.04 && $release_ver < 20.04" | bc) == 1 ]]; then
echo 'deb http://download.opensuse.org/repositories/home:/stig124:/nnn/xUbuntu_18.04/ /' | sudo tee /etc/apt/sources.list.d/nnn.list
curl -fsSL https://download.opensuse.org/repositories/home:stig124:nnn/xUbuntu_18.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_stig124_nnn.gpg >/dev/null
else
echo "The output of 'lsb_release -r' is not recognised. Please check."
exit 2
fi
# install
apt update
apt install nnn -y
# get the nano location using which
nano_loc="$(command -v nano)"
if [[ -z "$nano_loc" ]]; then
echo "Can't find nano"
exit 3
fi
{
# add the env vars to .bashrc
printf "\n"
printf "export EDITOR='%s'\n" "$nano_loc"
printf "export NNN_OPENER='%s'\n" "$nano_loc"
printf "export NNN_PLUG='l:!less \$nnn*;m:chmod_nnn;o:chown_nnn'\n"
} >>~/.bashrc
if [ -d "~.config/nnn/plugins" ]; then
wget "https://raw.githubusercontent.com/mahomedh/tmux_config/master/chmod_nnn.sh" -O "~.config/nnn/plugins/chmod_nnn.sh"
chmod +x "~.config/nnn/plugins/chmod_nnn.sh"
wget "https://raw.githubusercontent.com/mahomedh/tmux_config/master/chown_nnn.sh" -O "~.config/nnn/plugins/chown_nnn.sh"
chown +x "~.config/nnn/plugins/chmod_nnn.sh"
else
echo "ERROR: Plugins directory doesn't exist yet. Run nnn first then wget the plugins manually"
fi
# Add the script to enable 'cd on quit'
cat >>~/.bashrc <<-"NSCRIPT"
n() {
# Original script from https://github.com/jarun/nnn/blob/master/misc/quitcd/quitcd.bash_zsh
# Block nesting of nnn in subshells
if [[ "${NNNLVL:-0}" -ge 1 ]]; then
echo "nnn is already running"
return
fi
NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
# The backslash allows one to alias n to nnn if desired without making an
# infinitely recursive alias
\nnn -dHUcnx "$@"
if [ -f "$NNN_TMPFILE" ]; then
. "$NNN_TMPFILE"
rm -f "$NNN_TMPFILE" > /dev/null
ls -lhA
fi
unset NNN_TMPFILE
}
NSCRIPT
echo "Either run 'source ~/.bashrc' or exit the shell and log back in for changes to take effect"