Rewrite layout switcher in Nim #3
44
toggleGlobalMenu.nim
Normal file
44
toggleGlobalMenu.nim
Normal 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)
|
Loading…
Reference in New Issue
Block a user