themes kitten: ignore custom theme files if they are stdout

This commit is contained in:
Kovid Goyal 2023-04-17 08:02:41 +05:30
parent 91700b3e42
commit 046fbb860b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -829,7 +829,18 @@ func (self *Themes) add_from_dir(dirpath string) error {
}
for _, e := range entries {
if !e.IsDir() && strings.HasSuffix(e.Name(), ".conf") {
if _, err = self.AddFromFile(filepath.Join(dirpath, e.Name())); err != nil {
path := filepath.Join(dirpath, e.Name())
// ignore files if they are the current processes, stdout
// allows using kitten theme --dump-theme > ~/.config/kitty/themes/name.conf
if st, err := os.Stat(path); err == nil {
if st2, err := os.Stdout.Stat(); err == nil && os.SameFile(st, st2) {
continue
}
}
if path == os.Stdout.Name() {
continue
}
if _, err = self.AddFromFile(path); err != nil {
return err
}
}