Add toggleGlobalMenu.nim

This commit is contained in:
Rokosun 2023-12-25 07:54:45 +00:00
parent b7578dd97f
commit 87ae3a63f5

44
toggleGlobalMenu.nim Normal file
View File

@ -0,0 +1,44 @@
from std/os import paramCount, paramStr, extractFilename
from std/strformat import fmt
import sharedModule
proc enableGlobalMenus(): int =
return runCommand("/usr/bin/env", ["SKIP_AUTOSNAP=", "/usr/bin/pacman", "-S", "--noconfirm", "vala-panel-appmenu-registrar"])
proc disableGlobalMenus(): int =
result = runCommand("/usr/bin/env", ["SKIP_AUTOSNAP=", "/usr/bin/pacman", "-R", "--noconfirm", "vala-panel-appmenu-registrar"])
if result == 0:
discard runCommand("/usr/bin/killall", ["appmenu-registrar"])
proc showHelp() =
let executableName = paramStr(0).extractFilename()
echo fmt"""
Usage: {executableName} <option>
Options:
enable install global menus
disable remove global menus"""
var exitCode: int
if paramCount() < 1:
if isGlobalMenuEnabled():
exitCode = disableGlobalMenus()
else:
exitCode = enableGlobalMenus()
else:
case paramStr(1)
of "enable":
if isGlobalMenuEnabled():
echo "Global menus are already enabled."
exitCode = 0
else:
exitCode = enableGlobalMenus()
of "disable":
if not isGlobalMenuEnabled():
echo "Global menus are already disabled."
exitCode = 0
else:
exitCode = disableGlobalMenus()
else:
showHelp()
quit(exitCode)