-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathi3-navigation
executable file
·135 lines (96 loc) · 2.87 KB
/
i3-navigation
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
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
navigation_selection="${HOME}"
separator=" // "
font_name="Monospace"
font_size=10
font="${font_name}:size=${font_size}"
lines=60
prompt="NAVIGATION${separator}"
history_entry_count=3
history_file="${HOME}"/.local/bin/.i3-navigation-history
file_manager="ranger"
terminal="i3-sensible-terminal"
list="ls -a"
read="cat"
handler_open () {
xdg-open "${@}"
}
terminal_open () {
"${terminal}" -e "${@}"
}
terminal_open_visual () {
"${terminal}" -e "${file_manager} ${@}"
}
history_write () {
history_entry="${1}"
sed -i "\:${history_entry}:d" "${history_file}"
printf '%s\n' "${history_entry}" >> "${history_file}"
printf '%s\n' "$(tail -n "${history_entry_count}" "${history_file}")" > "${history_file}"
}
selections_parse () {
working_directory="${navigation_selection}"
label_selections_empty=''
label_selections_separator='////////////////////////////////////////////////////////////////////////////////'
label_selections_working_directory="DIRECTORY${separator}${working_directory}"
label_selections_history='[ History ] ↴'
label_selections_terminal='[ Open Terminal Here ]'
label_selections_terminal_visual='[ Open Visual Terminal Here ]'
selections=(
"${label_selections_working_directory}"
"${label_selections_empty}"
"${label_selections_terminal}"
"${label_selections_terminal_visual}"
"${label_selections_empty}"
"$(${list} "${navigation_selection}")"
"${label_selections_empty}"
"${label_selections_history}"
"${label_selections_empty}"
"$(${read} "${history_file}")"
)
IFS=$"\n"
for selection in "${selections[@]}"
do
echo "${selection}"
done
IFS=""
selections=()
}
while :
do
selection="$(selections_parse | dmenu -i -l "${lines}" -p "${prompt}" -fn "${font}" -nb '#000000' -nf '#FFFFFF' -sb '#666666' -sf '#000000' "${@}")" || exit 1
if [ "${selection}" == '[ Open Terminal Here ]' ]
then
terminal_open "${navigation_selection}"
history_write "${navigation_selection}"
elif [ "${selection}" == '[ Open Visual Terminal Here ]' ]
then
terminal_open_visual "${navigation_selection}"
history_write "${navigation_selection}"
elif [[ "${selection}" == '/'* ]]
then
navigation_selection="${selection}"
elif [[ "${selection}" =~ ^(https?|ftps): ]]
then
handler_open "${selection}"
history_write "${selection}"
else
navigation_selection="$(realpath "${navigation_selection}/${selection}")"
fi
if [ -f "${navigation_selection}" ] || [ "${selection}" = '.' ]
then
handler_open "${navigation_selection}"
history_write "${navigation_selection}"
elif [ -d "${navigation_selection}" ]
then
selections=(
"${label_selections_working_directory}"
"${label_selections_empty}"
"${label_selections_terminal}"
"${label_selections_terminal_visual}"
"${label_selections_empty}"
"$(${list} "${navigation_selection}")"
)
else
navigation_selection="$(dirname "${navigation_selection}")"
fi
done