mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 13:51:31 +00:00
Merge pull request #932 from luukvbaal/preview-tui
.iconlookup: refactor
This commit is contained in:
commit
df6dbbb84c
|
@ -6,24 +6,17 @@
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
# 1. Set colors and/or icons to your liking
|
# 1. Set colors and/or icons to your liking
|
||||||
# 2. preview-tui-ext uses the script to prepend icon to directory listings
|
# 2. Pipe any directory listing to iconlookup and it will output prepended icons
|
||||||
# 3. Aditionally you can consider adding it to your PATH and/or FZF_DEFAULT_COMMAND to
|
# 3. preview-tui-ext uses the script to prepend icon to directory listings
|
||||||
|
# 4. Aditionally you can consider adding it to your PATH and/or FZF_DEFAULT_COMMAND to
|
||||||
# make it work with various fzf plugins (make sure you also add --ansi to your FZF_DEFAULT_OPTS)
|
# make it work with various fzf plugins (make sure you also add --ansi to your FZF_DEFAULT_OPTS)
|
||||||
|
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
|
|
||||||
# Author: Luuk van Baal
|
# Author: Luuk van Baal (https://github.com/luukvbaal/iconlookup)
|
||||||
|
|
||||||
icon_lookup() {
|
icon_lookup() {
|
||||||
awk 'BEGIN { FS="." }
|
awk 'BEGIN {
|
||||||
{
|
|
||||||
if ($0 ~/^\.$/)
|
|
||||||
next
|
|
||||||
ent[NR] = $0
|
|
||||||
ext[NR] = $NF
|
|
||||||
limit = ENVIRON["limit"]
|
|
||||||
}
|
|
||||||
END {
|
|
||||||
# Set your ANSI colorscheme below (https://en.wikipedia.org/wiki/ANSI_escape_code#Colors).
|
# Set your ANSI colorscheme below (https://en.wikipedia.org/wiki/ANSI_escape_code#Colors).
|
||||||
# Default uses standard nnn icon colors, 8 and 24-bit nord themes are commented out.
|
# Default uses standard nnn icon colors, 8 and 24-bit nord themes are commented out.
|
||||||
colordepth=8 #colordepth=8 #colordepth=24
|
colordepth=8 #colordepth=8 #colordepth=24
|
||||||
|
@ -48,18 +41,6 @@ color_ruby=160 #color_ruby=150 #color_ruby="163;190;140"
|
||||||
color_scala=196 #color_scala=139 #color_scala="143;188;187"
|
color_scala=196 #color_scala=139 #color_scala="143;188;187"
|
||||||
color_vim=28 #color_vim=109 #color_vim="143;188;187"
|
color_vim=28 #color_vim=109 #color_vim="143;188;187"
|
||||||
|
|
||||||
switch (colordepth) {
|
|
||||||
case "4":
|
|
||||||
escape="\033["
|
|
||||||
break;
|
|
||||||
case "8":
|
|
||||||
escape="\033[38;5;"
|
|
||||||
break;
|
|
||||||
case "24":
|
|
||||||
escape="\033[38;2;"
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
# icons[][1] contains icon and icons[][2] contains color
|
# icons[][1] contains icon and icons[][2] contains color
|
||||||
icons["directory"][1] = ""; icons["directory"][2] = color_default
|
icons["directory"][1] = ""; icons["directory"][2] = color_default
|
||||||
icons["file"][1] = ""; icons["file"][2] = color_default
|
icons["file"][1] = ""; icons["file"][2] = color_default
|
||||||
|
@ -303,35 +284,53 @@ color_vim=28 #color_vim=109 #color_vim="143;188;187"
|
||||||
# z
|
# z
|
||||||
icons["zip"][1] = icons["archive"][1]; icons["zip"][2] = icons["archive"][2]
|
icons["zip"][1] = icons["archive"][1]; icons["zip"][2] = icons["archive"][2]
|
||||||
|
|
||||||
|
FS = "."
|
||||||
|
limit = ENVIRON["limit"]
|
||||||
|
switch (colordepth) {
|
||||||
|
case "4":
|
||||||
|
escape="\033["
|
||||||
|
break;
|
||||||
|
case "8":
|
||||||
|
escape="\033[38;5;"
|
||||||
|
break;
|
||||||
|
case "24":
|
||||||
|
escape="\033[38;2;"
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# dont print cwd . and leading ./ from tree -f
|
||||||
|
if ($0 ~/^\.$/)
|
||||||
|
next
|
||||||
|
ent = ($0 ~/^\.\//) ? substr($0, 3, length($0) - 2) : $0
|
||||||
|
ext = $NF
|
||||||
# Print icons, set color and bold directories by using ansi escape codes
|
# Print icons, set color and bold directories by using ansi escape codes
|
||||||
for (i in ent)
|
if (ext in icons)
|
||||||
if (ext[i] in icons)
|
printcolor(icons[ext][1], icons[ext][2], color_filetxt, ent, "10")
|
||||||
printcolor(icons[ext[i]][1], icons[ext[i]][2], color_filetxt, ent[i], "10")
|
|
||||||
else
|
else
|
||||||
switch (substr(ent[i], length(ent[i]), 1)) {
|
switch (substr(ent, length(ent), 1)) {
|
||||||
case "/":
|
case "/":
|
||||||
printcolor(icons["directory"][1], color_default, color_dirtxt, ent[i], "1")
|
printcolor(icons["directory"][1], color_default, color_dirtxt, ent, "1")
|
||||||
break;
|
break;
|
||||||
case "*":
|
case "*":
|
||||||
printcolor(icons["exe"][1], color_default, color_filetxt, ent[i], "10")
|
printcolor(icons["exe"][1], color_default, color_filetxt, ent, "10")
|
||||||
break;
|
break;
|
||||||
case "|":
|
case "|":
|
||||||
printcolor(icons["pipe"][1], color_default, color_filetxt, ent[i], "10")
|
printcolor(icons["pipe"][1], color_default, color_filetxt, ent, "10")
|
||||||
break;
|
break;
|
||||||
case "=":
|
case "=":
|
||||||
printcolor(icons["socket"][1], color_default, color_filetxt, ent[i], "10")
|
printcolor(icons["socket"][1], color_default, color_filetxt, ent, "10")
|
||||||
break;
|
break;
|
||||||
case ">":
|
case ">":
|
||||||
printcolor(icons["door"][1], color_default, color_filetxt, ent[i], "10")
|
printcolor(icons["door"][1], color_default, color_filetxt, ent, "10")
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printcolor(icons["file"][1], color_default, color_filetxt, ent[i], "10")
|
printcolor(icons["file"][1], color_default, color_filetxt, ent, "10")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function printcolor(i, c, d, n, b) {
|
function printcolor(i, c, d, n, b) {
|
||||||
if (limit != "" && length(n) + 2 > limit)
|
if (limit != "" && length(n) + 2 > limit)
|
||||||
n = substr(n, 1, ENVIRON["limit"] - 2)
|
n = substr(n, 1, limit - 2)
|
||||||
printf "\033[0m"
|
printf "\033[0m"
|
||||||
printf "%s%s;%sm%s %s%sm%s\n", escape, c, b, i, escape, d, n
|
printf "%s%s;%sm%s %s%sm%s\n", escape, c, b, i, escape, d, n
|
||||||
}'
|
}'
|
||||||
|
|
Loading…
Reference in a new issue