hyprland/module: add edit command

parent 665125fd
......@@ -24,6 +24,8 @@ complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and __fish_seen_subcommand_from get' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and __fish_seen_subcommand_from unset' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from check' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from edit' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from enable' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from disable' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from toggle' -f -a '(__fish_ximperconf_complete)'
......@@ -61,16 +63,20 @@ complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and not __fish_seen_subcommand_from check sync-xkb-layouts module var plugin' -a 'module' -d 'Hyprland modules'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module' -f -l user -s u -d 'use user modules'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from status info enable disable toggle' -a 'status' -d 'Hyprland module status'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from check edit status info enable disable toggle' -a 'check' -d 'Check Hyprland module'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from check' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from check edit status info enable disable toggle' -a 'edit' -d 'Edit module file'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from edit' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from check edit status info enable disable toggle' -a 'status' -d 'Hyprland module status'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from status' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from status info enable disable toggle' -a 'info' -d 'Information about modules'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from check edit status info enable disable toggle' -a 'info' -d 'Information about modules'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from info' -f -l filter -s f -r -d 'status filter'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from info' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from status info enable disable toggle' -a 'enable' -d 'enable module'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from check edit status info enable disable toggle' -a 'enable' -d 'enable module'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from enable' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from status info enable disable toggle' -a 'disable' -d 'disable module'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from check edit status info enable disable toggle' -a 'disable' -d 'disable module'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from disable' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from status info enable disable toggle' -a 'toggle' -d 'toggle module'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from check edit status info enable disable toggle' -a 'toggle' -d 'toggle module'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from toggle' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and not __fish_seen_subcommand_from check sync-xkb-layouts module var plugin' -a 'var' -d 'Hyprland vars'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var' -f -l help -s h -d 'show help'
......
......@@ -464,6 +464,32 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
return nil
}
func HyprlandModuleEditCommand(ctx context.Context, cmd *cli.Command) error {
module := cmd.Args().Get(0)
user := cmd.Bool("user")
modulefile := HyprlandGetModuleFile(module, user)
if !utils.FileExists(modulefile) {
color.Red("Модуль '%s' не найден: %s", module, modulefile)
return nil
}
editor := utils.GetEditor()
editCmd := exec.Command(editor, modulefile)
editCmd.Stdin = os.Stdin
editCmd.Stdout = os.Stdout
editCmd.Stderr = os.Stderr
err := editCmd.Run()
if err != nil {
color.Red("Не удалось запустить редактор: %s", err.Error())
return err
}
return nil
}
func hyprlandModuleLines(module string, user bool) (sysFile, lineFull, lineTilde string) {
sysFile = HyprlandGetModuleFile(module, user)
lineFull = "source = " + sysFile
......
......@@ -52,6 +52,13 @@ func CommandList() *cli.Command {
ShellComplete: ShellCompleteModule("all"),
},
{
Name: "edit",
Usage: "Edit module file",
ArgsUsage: "module",
Action: HyprlandModuleEditCommand,
ShellComplete: ShellCompleteModule("all"),
},
{
Name: "status",
Usage: "Hyprland module status",
ArgsUsage: "module",
......
......@@ -6,3 +6,10 @@ func FileExists(path string) bool {
_, err := os.Stat(path)
return err == nil
}
func GetEditor() string {
if editor := os.Getenv("EDITOR"); editor != "" {
return editor
}
return "micro"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment