added command_wrapper for various other dmenu styled tools

This commit is contained in:
Paul Wilde 2022-05-06 12:07:22 +01:00
parent 42a9b61a5b
commit 9639b17cbe
4 changed files with 68 additions and 21 deletions

View file

@ -5,16 +5,18 @@ about system status in dmenu. Some of them i.e. `volume` have options (up, down,
which are selectable options in dmenu.
## Tools
- `pingclock` performs a single `ping` to a server and returns the response time
- `battery` shows the current battery level
- `brightness` shows the current backlight level and gives options to adjust it
- `volume` shows the current volume level and gives options to adjust and manage it
- `date` shows the date
- `fuzzytime` shows the fuzzytime clock
- `wlan` shows the state of the wireless network interface. SSID connected to and signal level.
- `nic` shows the status and/or the ip address of the network interface card
- `temperature` shows the current CPU temperature
- `notes` a simple one liner note taking tool, displaying notes in dmenu/rofi
- `pingclock` performs a single `ping` to a server and returns the response time
- `battery` shows the current battery level
- `brightness` shows the current backlight level and gives options to adjust it
- `volume` shows the current volume level and gives options to adjust and manage it
- `date` shows the date
- `fuzzytime` shows the fuzzytime clock
- `wlan` shows the state of the wireless network interface. SSID connected to and signal level.
- `nic` shows the status and/or the ip address of the network interface card
- `temperature` shows the current CPU temperature
- `notes` a simple one liner note taking tool, displaying notes in dmenu/rofi
- `passmenu_wrapper` a wrapper for passmenu. It basically just styles passmenu with no other features
- `command_wrapper` inspired by passmenu_wrapper, a basic tool to run other dmenu related tools with uniform styling
### Example in dmenu:

View file

@ -59,6 +59,9 @@ var loop* = false
var stoploop* = true
var dmenu* = true
var rofi* = false
var passmenu* = false
var command_wrapper* = false
var run_command* = ""
proc newInfo*(title: string = "Info"): Info =
return Info(
@ -73,9 +76,9 @@ proc newInfo*(title: string = "Info"): Info =
color: foreground,
)
proc newDmenuConfig(): Dmenu =
proc newDmenuConfig(cmd: string = "dmenu"): Dmenu =
var dmenu = Dmenu()
dmenu.command = "dmenu"
dmenu.command = cmd
dmenu.bottom = "-b"
dmenu.grabkb = "-f"
dmenu.i_case = "-i"
@ -97,6 +100,10 @@ proc newRofiConfig(): Dmenu =
proc newDmenu(): Dmenu =
if rofi:
return newRofiConfig()
elif passmenu:
return newDmenuConfig("passmenu")
elif command_wrapper:
return newDmenuConfig(run_command)
return newDmenuConfig()
proc debugLog*(str: string) =
@ -137,13 +144,7 @@ proc quote*(str: string): string =
return " \"" & text & "\" "
# ^ Add a spaces ^ so the previous flag isn't touching
proc getLines(num: int): int =
if num > MAX_LINES:
return MAX_LINES
return num + 1
proc runDMenu*(data: Info, opts: varargs[string], rofi: bool = false): string =
proc genDmenuCmd*(data: Info, opts: varargs[string], rofi: bool = false): string =
# Build dmenu/rofi command
var cmd = ""
# if the text is empty, we don't want to create a menu item of it
@ -157,14 +158,19 @@ proc runDMenu*(data: Info, opts: varargs[string], rofi: bool = false): string =
var dmenu = newDmenu()
cmd = cmd & dmenu.command & " "
cmd = cmd & dmenu.lines_shown & " " & $20 & " "
cmd = cmd & dmenu.lines_shown & " " & $MAX_LINES & " "
cmd = cmd & dmenu.prompt & quote(data.title)
cmd = cmd & dmenu.norm_bg & quote(data.unselected_bg)
cmd = cmd & dmenu.norm_fg & quote(data.unselected_fg)
cmd = cmd & dmenu.sel_bg & quote(data.selected_bg)
cmd = cmd & dmenu.sel_fg & quote(data.selected_fg)
cmd = cmd & dmenu.font & quote(font)
return cmd
proc runDMenu*(data: Info, opts: varargs[string], rofi: bool = false): string =
let cmd = genDmenuCmd(data, opts, rofi)
#echo cmd
#
# Run command and get output
@ -194,7 +200,8 @@ proc outputData*(data: Info, args: varargs[string]): string {.discardable.} =
# Switch bindsym mode back to default as it could be being used.
switchTwmMode()
for arg in getArguments():
let args* = getArguments()
for idx, arg in args:
case arg:
of "noloop":
stoploop = true
@ -209,5 +216,8 @@ for arg in getArguments():
of "rofi":
stoploop = true
rofi = true
of ["pass","passmenu"]:
passmenu = true
break

22
command_wrapper.nim Normal file
View file

@ -0,0 +1,22 @@
import base
import std/[strutils,osproc]
# Basically just a wrapper to style passmenu nicely
proc main() =
var info = newInfo(capitalizeAscii(run_command))
let cmd = genDmenuCmd(info)
discard execCmd(cmd)
return
if isMainModule:
base.command_wrapper = true
for idx, arg in args:
case arg:
of "-r", "--run":
run_command = args[idx + 1]
else:
echo "No run tag given. Please run again with '--run _cmd_'"
break
if run_command != "":
main()

13
passmenu_wrapper.nim Normal file
View file

@ -0,0 +1,13 @@
import base
import std/osproc
# Basically just a wrapper to style passmenu nicely
proc main() =
var info = newInfo("Passmenu")
let cmd = genDmenuCmd(info)
discard execCmd(cmd)
return
if isMainModule:
passmenu = true
main()