File tree 3 files changed +105
-23
lines changed
3 files changed +105
-23
lines changed Original file line number Diff line number Diff line change
1
+ package icon
2
+
3
+ import (
4
+ "path/filepath"
5
+ )
6
+
7
+ // ForFile - Return rune icon corresponding to input file name
8
+ func ForFile (name string ) rune {
9
+ ext := filepath .Ext (name )
10
+ if len (ext ) == 0 { return files ["file" ] }
11
+ icon := files [ext [1 :]]
12
+ if icon == 0 { return files ["file" ] }
13
+ return icon
14
+ }
15
+
16
+ var files = map [string ]rune {
17
+ "ai" : '\ue7b4' ,
18
+ "android" : '\ue70e' ,
19
+ "apple" : '\uf179' ,
20
+ "audio" : '\uf001' ,
21
+ "avro" : '\ue60b' ,
22
+ "c" : '\ue61e' ,
23
+ "clj" : '\ue768' ,
24
+ "coffee" : '\uf0f4' ,
25
+ "conf" : '\ue615' ,
26
+ "cpp" : '\ue61d' ,
27
+ "css" : '\ue749' ,
28
+ "d" : '\ue7af' ,
29
+ "dart" : '\ue798' ,
30
+ "db" : '\uf1c0' ,
31
+ "diff" : '\uf440' ,
32
+ "doc" : '\uf1c2' ,
33
+ "docker" : '\uf308' ,
34
+ "ebook" : '\ue28b' ,
35
+ "env" : '\uf462' ,
36
+ "epub" : '\ue28a' ,
37
+ "erl" : '\ue7b1' ,
38
+ "file" : '\uf15b' ,
39
+ "font" : '\uf031' ,
40
+ "gform" : '\uf298' ,
41
+ "git" : '\uf1d3' ,
42
+ "go" : '\ue626' ,
43
+ "gruntfile.js" : '\ue74c' ,
44
+ "hs" : '\ue777' ,
45
+ "html" : '\uf13b' ,
46
+ "image" : '\uf1c5' ,
47
+ "iml" : '\ue7b5' ,
48
+ "java" : '\ue204' ,
49
+ "js" : '\ue74e' ,
50
+ "json" : '\ue60b' ,
51
+ "jsx" : '\ue7ba' ,
52
+ "less" : '\ue758' ,
53
+ "log" : '\uf18d' ,
54
+ "lua" : '\ue620' ,
55
+ "md" : '\uf48a' ,
56
+ "mustache" : '\ue60f' ,
57
+ "npmignore" : '\ue71e' ,
58
+ "pdf" : '\uf1c1' ,
59
+ "php" : '\ue73d' ,
60
+ "pl" : '\ue769' ,
61
+ "ppt" : '\uf1c4' ,
62
+ "psd" : '\ue7b8' ,
63
+ "py" : '\ue606' ,
64
+ "r" : '\uf25d' ,
65
+ "rb" : '\ue21e' ,
66
+ "rdb" : '\ue76d' ,
67
+ "rss" : '\uf09e' ,
68
+ "rubydoc" : '\ue73b' ,
69
+ "sass" : '\ue603' ,
70
+ "scala" : '\ue737' ,
71
+ "shell" : '\uf489' ,
72
+ "sqlite3" : '\ue7c4' ,
73
+ "styl" : '\ue600' ,
74
+ "tex" : '\ue600' ,
75
+ "ts" : '\ue628' ,
76
+ "twig" : '\ue61c' ,
77
+ "txt" : '\uf15c' ,
78
+ "video" : '\uf03d' ,
79
+ "vim" : '\ue62b' ,
80
+ "windows" : '\uf17a' ,
81
+ "xls" : '\uf1c3' ,
82
+ "xml" : '\ue619' ,
83
+ "yarn.lock" : '\ue718' ,
84
+ "yml" : '\uf481' ,
85
+ "zip" : '\uf410' ,
86
+ }
Original file line number Diff line number Diff line change
1
+ package icon
2
+
3
+ // ForFolder - Return rune icon corresponding to input folder name
4
+ func ForFolder (name string ) rune {
5
+ return '\uf115'
6
+ }
Original file line number Diff line number Diff line change @@ -4,27 +4,11 @@ import (
4
4
"os"
5
5
"log"
6
6
"fmt"
7
- "path/filepath"
8
7
"io/ioutil"
9
8
"github.com/fatih/color"
9
+ "github.com/drn/nerd-ls/icon"
10
10
)
11
11
12
- var icons = map [string ]rune {
13
- ".DS_Store" : '' ,
14
- ".bash_history" : '' ,
15
- ".bash_profile" : '' ,
16
- ".conf" : '' ,
17
- ".env" : '' ,
18
- ".git" : '' ,
19
- ".go" : '' ,
20
- ".js" : '' ,
21
- ".json" : '' ,
22
- ".md" : '' ,
23
- ".rb" : '' ,
24
- ".yml" : '' ,
25
- "dir" : '' ,
26
- }
27
-
28
12
// Node - Contains all info necessary to render file or directory
29
13
type Node struct {
30
14
Name string
@@ -64,14 +48,20 @@ func new(file os.FileInfo) Node {
64
48
func rawName (file os.FileInfo ) string {
65
49
suffix := ""
66
50
if file .IsDir () { suffix = "/" }
67
- return fmt .Sprintf ("%c %s%s " , icon (file ), file .Name (), suffix )
51
+
52
+ return fmt .Sprintf (
53
+ "%c %s%s " ,
54
+ fetchIcon (file ),
55
+ file .Name (),
56
+ suffix ,
57
+ )
68
58
}
69
59
70
- func icon (file os.FileInfo ) rune {
71
- if file .IsDir () { return icons [ "dir" ] }
72
- icon := icons [ filepath . Ext (file .Name ())]
73
- if icon == 0 { return ' ' }
74
- return icon
60
+ func fetchIcon (file os.FileInfo ) rune {
61
+ if file .IsDir () {
62
+ return icon . ForFolder (file .Name ())
63
+ }
64
+ return icon . ForFile ( file . Name ())
75
65
}
76
66
77
67
func colorize (file os.FileInfo , name string ) string {
You can’t perform that action at this time.
0 commit comments