ls -l 第一位 文件类型 gokcehan/lf 颜色

ls -l

Symbol File Type
regular file
d directory
l symbolic link
p named pipe
c character devicee.g., /dev/tty1
b block devicee.g., /dev/sda2
s

socket

 

lf

默认 lf 颜色主要取自 GNU dircolors 默认值。这些默认值使用 8 种基本颜色和粗体属性。具有背景颜色的默认 dircolors 条目已被简化,以避免与 lf 中的当前文件选择混淆。同样,为了简单起见,只有文件类型匹配,而省略了扩展名匹配。默认值如下所示,并在 lf 中给出匹配顺序:

ln  01;36
or  31;01
tw  01;34
ow  01;34
st  01;34
di  01;34
pi  33
so  01;35
bd  33;01
cd  33;01
su  01;32
sg  01;32
ex  01;32
fi  00

 

34 表示蓝色文字

tw 01;34 ow 01;34 st 01;34 di 01;34

tw    STICKY_OTHER_WRITABLE    Directory that is sticky and other-writable (+t,o+w)

ow    OTHER_WRITABLE    Directory that is other-writable (o+w) and not sticky

di    DIR    Directory

 

36 表示青色文字

ln 01;36

ln    SYMLINK, LINK, LNK    Symbolic link. If you set this to 'target' instead of a numerical value, the colour is as for the file pointed to.

 

00    Default colour 白色

fi    FILE    Normal file

 

32 表示绿色文字

su 01;32 sg 01;32 ex 01;32

su    SETUID    File that is setuid (u+s)
sg    SETGID    File that is setgid (g+s)

ex    EXEC    Executable file (i.e. has 'x' set in permissions)

 

31 表示红色文字

or 31;01

or    ORPHAN    Symbolic link pointing to a non-existent file

 

 

33 表示黄色文字

pi 33 bd 33;01 cd 33;01

pi    FIFO, PIPE    Named pipe

 

 

Dcrw-------

Drw-------

看了源码也没搞明白这个Dc和D是怎么来的

翻了翻找到怎么来的了

https://cs.opensource.google/go/go/+/refs/tags/go1.22.0:src/os/types.go;l=28

// The defined file mode bits are the most significant bits of the FileMode.
// The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
// The values of these bits should be considered part of the public API and
// may be used in wire protocols or disk representations: they must not be
// changed, although new bits might be added.
const (
// The single letters are the abbreviations
// used by the String method's formatting. 单个字母是String方法格式化时使用的缩写。
ModeDir = fs.ModeDir // d: is a directory
ModeAppend = fs.ModeAppend // a: append-only
ModeExclusive = fs.ModeExclusive // l: exclusive use
ModeTemporary = fs.ModeTemporary // T: temporary file; Plan 9 only
ModeSymlink = fs.ModeSymlink // L: symbolic link
ModeDevice = fs.ModeDevice // D: device file
ModeNamedPipe = fs.ModeNamedPipe // p: named pipe (FIFO)
ModeSocket = fs.ModeSocket // S: Unix domain socket
ModeSetuid = fs.ModeSetuid // u: setuid
ModeSetgid = fs.ModeSetgid // g: setgid
ModeCharDevice = fs.ModeCharDevice // c: Unix character device, when ModeDevice is set
ModeSticky = fs.ModeSticky // t: sticky
ModeIrregular = fs.ModeIrregular // ?: non-regular file; nothing else is known about this file
 
// Mask for the type bits. For regular files, none will be set.
ModeType = fs.ModeType
 
ModePerm = fs.ModePerm // Unix permission bits, 0o777
)

 

https://pkg.go.dev/os#FileMode

https://pkg.go.dev/github.com/gogf/gf/internal/fileinfo#Info.Mode

https://stackoverflow.com/questions/48123541/how-does-the-go-language-os-filemode-function-convert-permissions-from-integers

fi.Mode().String()

 

 

https://github.com/gokcehan/lf/blob/master/ui.go

func (ui *ui) loadFileInfo(nav *nav) {
  if !nav.init {
    return
  }

  curr, err := nav.currFile()
  if err != nil {
    return
  }

  if curr.err != nil {
    ui.echoerrf("stat: %s", curr.err)
    return
  }

  statfmt := strings.ReplaceAll(gOpts.statfmt, "|", "\x1f")
  replace := func(s string, val string) {
    if val == "" {
      val = "\x00"
    }
    statfmt = strings.ReplaceAll(statfmt, s, val)
  }
  replace("%p", curr.Mode().String())
  replace("%c", linkCount(curr))
  replace("%u", userName(curr))
  replace("%g", groupName(curr))
  replace("%s", humanize(curr.Size()))
  replace("%S", fmt.Sprintf("%4s", humanize(curr.Size())))
  replace("%t", curr.ModTime().Format(gOpts.timefmt))
  replace("%l", curr.linkTarget)

  fileInfo := ""
  for _, section := range strings.Split(statfmt, "\x1f") {
    if !strings.Contains(section, "\x00") {
      fileInfo += section
    }
  }

  ui.msg = fileInfo
  ui.msgIsStat = true
}
posted @ 2024-02-18 12:37  hrdom  阅读(6)  评论(0编辑  收藏  举报