Jelovnik is fast, simple, "less than 100 lines of code" keyboard-warrior's open-source menu system for rapid-development of console menus. All you have to do is write few CSV lines to a file and enjoy.
I needed a menu system which will allow me to quickly add/remove menu items without wondering around through numerous lines of code or risking to break perfectly functioning menu by doing a small change. I was using otherwise uberpowerful AutoHotKey for that purpose, but for some reason I never managed to get used to AHK's menu system.
Powershell 7 console, Windows. Could be made compatible with Powershell 5, but IMHO every Powershell keyboard warrior should have v.7 anyway, so...
"System" consists of a script and at least one menu file. Menu file contains info about hot-keys and associated commands. It may be convenient to assign a Windows or Autohotkey shortcut key to start menu.
C:\Program Files\PowerShell\7\pwsh.exe -file jelovnik.ps1 main_menu.csv
After pressing a hot-key, script will execute an assigned command and exit (unless the command is "LoadMenu" in which case it will open next menu). This behavior can be changed run a command and to stay in the same menu ("loop") until ESC is pressed; see below.
"Menu file" is a simple text, comma separated file (actually, pipe separated, "|") of any name with .CSV extension.
You can have as many menu files as you wish.
You can create as many levels of menus as needed.
There must be at least one item in a menu file.
There can be 62 items in a single menu file as hotkeys are [a..z], [A..Z] and [0..9].
Left arrow
(go back in history of submenus) works only with one level.
Currently, script ends after a hot-key is pressed and command executed. Behavior can be changed to "loop until ESC is pressed" by changing this line:
Default { Start-Process $script:Jelovnik[$j].Command.Trim() -ArgumentList $script:Jelovnik[$j].Parameters.Trim(); EXIT }
to this:
Default { Start-Process $script:Jelovnik[$j].Command.Trim() -ArgumentList $script:Jelovnik[$j].Parameters.Trim() }
(in short: remove ; EXIT
). Now script will run a command and stay in the current menu file. Exit by pressing "ESC".
CSV files have four fields:
Field | Description |
---|---|
Key | Menu hot-key |
Title | Title of an item in menu |
Command | Command to execute |
Parameters | Arguments for a command |
("Key" is case-sensitive character, or number)
Example row from a menu file:
c|Calculator|cmd|/c calc.exe
Items | Description |
---|---|
c | When user presses "c" on keyboard.. |
Calculator | ..in a line titled "Calculator".. |
cmd | ..execute this command.. |
/c calc.exe | ..with these arguments |
There are several special keys / commands in menu-file:
- Command
<LOADMENU>
... loads another menu-file - Command
<ASK>
... executes a Powershell command, but first displays that command and asks for confirmation "Execute?" - Command
<PS1>
... executes other pwsh script; added because of problems with pwsh on Linux - Command
<BASH>
... executes a bash script - Key
-
... draws a separator line; do not add a separator as first or last item in menu as it doesn't makes sense and script doesn't check this - it will simply exit with error
There are several keyboard commands:
Escape
... exits the scriptLeft cursor
... returns to previous menu level**Down cursor
andUp cursor
... moves through menu down / upHome
andEnd
... jumps to first / last item in menuEnter
orRight cursor
... executes command on currently selected line; opens submenu!
... opens current menu-file in notepad to edit it "on the fly"; after saving file just restart it or press Space to reloadF1
... displays help-file; help file must have ".help" extensionin addition to a full file-name (e.g. "main_menu.csv.help")
**While you can have endless sublevels of menus, script remembers only one "previous menu". If you need an option to go back to Main menu from let's say 4th level of submenus - just add an item "0 - Main menu" and command LOADMENU Main_menu.
In Windows, you can simulate Midnight Commander ".mc.menu" functionality. Example:
- edit "jelovnik-mc_menu-emulator.cmd" and change path for "pwsh.exe" and script "jelovnik.ps1":
- "C:\Program Files\PowerShell\7\pwsh.exe"
- "E:\Dev21\Jelovnik.PS1\Jelovnik.ps1"
- save :)
- give your menu files extensions ".jelovnik", let's say ".00.jelovnik"
- right click on ".00.jelovnik"
- select "Open with.."
- choose "Look for another app on this PC"
- browse to attached "jelovnik-mc_menu-emulator.cmd" batch file
- select it and coose "Always use this app to open .jelovnik files..."
If you made everything OK, now you can have as many menu files as you wish in every folder and you can simply double click on them to open folder specific menu.
- (not aware of any)
- (no high priority ideas)
- Add keyboard command
?
... search for a command through all .CSV files - Add new column, "Description" which will, well, contain a description of menu command; very low priority
- Add more levels of submenu history (currently: 1)
- Use mouse - move cursor, read mouse location, click in Powershell console?
- Yes, it seems posible. This will read current mouse position (in pixels, not in columns rows):
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.Cursor]::Position
c|Calculator (cmd /c) |cmd |/c calc.exe
C|Calculator (direct) |calc.exe |-
k|NirCmd clipboard |cmd |/c nircmd.exe infobox "~$clipboard$" "Clipboard content"
K|Powershell clipboard |powershell |-command "Write-Host Clipboard=(get-clipboard); TIMEOUT.exe 999"
n|Notepad example.txt |cmd |/c notepad.exe example.txt
a|Ask before executing PWSH |<ASK> |Write-Host Clipboard=(get-clipboard); Write-Host "SecondLine"
d|example.txt |example.txt |-
g|github - Default browser |https://github.com |-
i|github - Internet Explorer |cmd |/c start iexplore https://github.com
-|Insert a separator line |- |-
2|>>> Menu 2 >>> |<LOADMENU> |menu2.csv
Jelovnik.PS1 v.21.0727.07
(C)2021 SomwareHR
https://github.com/SomwareHR
License: MIT
[SWID#20210725123801]
- Version 20211220 jelovnik.ps1 sha256:741D75F522CC0B70F48362C702B94A628FD11E88671017165AFD79ED6E8CA18C
*Jelovnik = "menu" on Croatian