Rewrite layout switcher in Nim #3

Merged
tio merged 8 commits from nim-rewrite into master 2023-12-26 00:08:43 +00:00
Showing only changes of commit 87ae3a63f5 - Show all commits

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)