Add emacs.desktop file and icon

master
Hugo Thunnissen 12 months ago
parent 7240e0573b
commit 0158da9990

@ -0,0 +1,29 @@
[Desktop Entry]
Type=Application
Name=Emacs
GenericName=Emacs Editor
Icon=emacs
Comment=Open an emacs frame through the running daemon
Exec={{.workspace_bin}} run emacsclient -c %F
StartupWMClass=Emacs
Version=1.0
Terminal=false
Categories=Development;TextEditor;IDE;WebDevelopment;GTK;
Keywords=Text;Editor;IDE;scratch;
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;inode/directory;
Actions=NewWindow;NewFile;NewInstance
[Desktop Action NewWindow]
Name=New Window
Exec={{.workspace_bin}} run emacsclient -c %F
[Desktop Action NewInstance]
Name=New Instance
Exec={{.workspace_bin}} run -privileged emacs %F
[Desktop Action NewFile]
Name=New File
Exec={{.workspace_bin}} run emacsclient -c -e '(switch-to-buffer (generate-new-buffer "new"))' %F

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

@ -2,6 +2,7 @@ package main
import ( import (
"bufio" "bufio"
"bytes"
_ "embed" _ "embed"
"errors" "errors"
"flag" "flag"
@ -10,10 +11,12 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/user" "os/user"
"path"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"syscall" "syscall"
"text/template"
) )
const usage = `workspace - Use a containerized workspace const usage = `workspace - Use a containerized workspace
@ -35,6 +38,12 @@ var customLisp string
//go:embed emacs/epaper-theme.el //go:embed emacs/epaper-theme.el
var elispEpaperTheme string var elispEpaperTheme string
//go:embed emacs/emacs.desktop
var emacsDesktop string
//go:embed emacs/emacs.png
var emacsIcon []byte
//go:embed bash/bash_aliases //go:embed bash/bash_aliases
var bashAliases string var bashAliases string
@ -317,16 +326,24 @@ func SetEnvVars() {
os.Setenv("PATH", "/usr/local/go/bin:"+os.Getenv("PATH")) os.Setenv("PATH", "/usr/local/go/bin:"+os.Getenv("PATH"))
os.Setenv("PATH", "/usr/local/gopkg/bin:"+os.Getenv("PATH")) os.Setenv("PATH", "/usr/local/gopkg/bin:"+os.Getenv("PATH"))
os.Setenv("GOPRIVATE", "git.snorba.art") os.Setenv("GOPRIVATE", "git.snorba.art")
os.Setenv("EMACS_SOCKET_NAME", home+"/.cache/emacs/server")
} }
func DumpStringToFile(data string, path string) error { func DumpBytesToFile(data []byte, filePath string) error {
file, err := os.Create(path) fmt.Fprintln(os.Stderr, "Dumping to "+filePath)
err := EnsureDirectory(path.Dir(filePath))
if err != nil {
return err
}
file, err := os.Create(filePath)
if err != nil { if err != nil {
return err return err
} }
writer := bufio.NewWriter(file) writer := bufio.NewWriter(file)
_, err = writer.WriteString(data) _, err = writer.Write(data)
if err != nil { if err != nil {
return err return err
} }
@ -334,6 +351,10 @@ func DumpStringToFile(data string, path string) error {
return writer.Flush() return writer.Flush()
} }
func DumpStringToFile(data string, path string) error {
return DumpBytesToFile([]byte(data), path)
}
func ToggleNightLight() error { func ToggleNightLight() error {
getState := exec.Command( getState := exec.Command(
"gsettings", "gsettings",
@ -368,22 +389,26 @@ func ToggleNightLight() error {
return nil return nil
} }
func DumpInitFiles() error { func EnsureDirectory(dir string) error {
home := os.Getenv("HOME") if _, err := os.Stat(dir); os.IsNotExist(err) {
elispThemeDir := home + "/.workspace/elisp-themes" err = os.MkdirAll(dir, 0755)
if _, err := os.Stat(elispThemeDir); os.IsNotExist(err) {
err = os.MkdirAll(elispThemeDir, 0755)
if err != nil { if err != nil {
return fmt.Errorf( return fmt.Errorf(
"Failed to create elisp theme dir in %v: %w", "Failed to create dir %v: %w",
elispThemeDir, dir,
err, err,
) )
} }
} }
return nil
}
func DumpInitFiles() error {
home := os.Getenv("HOME")
elispThemeDir := home + "/.workspace/elisp-themes"
err := EnsureDirectory(elispThemeDir)
files := map[string]string{ files := map[string]string{
home + "/.emacs": initLisp, home + "/.emacs": initLisp,
home + "/.custom.el": customLisp, home + "/.custom.el": customLisp,
@ -394,14 +419,39 @@ func DumpInitFiles() error {
} }
for file, contents := range files { for file, contents := range files {
fmt.Fprintln(os.Stderr, "Dumping to "+file)
err := DumpStringToFile(contents, file) err := DumpStringToFile(contents, file)
if err != nil { if err != nil {
return err return err
} }
} }
return nil tmp, err := template.New("emacs.desktop").Parse(emacsDesktop)
if err != nil {
return err
}
executable, err := os.Executable()
if err != nil {
return err
}
var out bytes.Buffer
tmp.Execute(&out, map[string]string{
"workspace_bin": executable,
})
err = DumpBytesToFile(
out.Bytes(), home+"/.local/share/applications/emacs.desktop",
)
if err != nil {
return err
}
return DumpBytesToFile(
emacsIcon,
home+"/.local/share/icons/hicolor/128x128/apps/emacs.png",
)
} }
func main() { func main() {

Loading…
Cancel
Save