Skip to content

Commit 1d00fcb

Browse files
committed
make the zhs autocompletion more dynamic
Signed-off-by: Zen <[email protected]>
1 parent 16d453f commit 1d00fcb

File tree

4 files changed

+33
-46
lines changed

4 files changed

+33
-46
lines changed

completion/_ugrd

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
11
#compdef ugrd
22

3-
_arguments \
4-
'--build-logging[Enable additional build logging.]' \
5-
'--no-build-logging[Disable additional build logging.]' \
6-
'-c[Config file location.]:config file:_files' \
7-
'--config[Config file location.]:config file:_files' \
8-
'--kernel-version[Set the kernel version.]:kernel version:_files -W /lib/modules -/' \
9-
'--kver[Set the kernel version.]:kernel version:_files -W /lib/modules -/' \
10-
'--clean[Enable build directory cleaning.]' \
11-
'--no-clean[Disable build directory cleaning.]' \
12-
'--validate[Enable config validation.]' \
13-
'--no-validate[Disable config validation.]' \
14-
'--hostonly[Enable hostonly mode, required for automatic kmod detection.]' \
15-
'--no-hostonly[Disable hostonly mode.]' \
16-
'--lspci[Use lspci to auto-detect kmods]' \
17-
'--no-lspci[Do not use lspci to auto-detect kmods]' \
18-
'--lsmod[Use lsmod to auto-detect kmods]' \
19-
'--no-lsmod[Do not use lsmod to auto-detect kmods]' \
20-
'--firmware[Include firmware files found with modinfo.]' \
21-
'--no-firmware[Exclude firmware files.]' \
22-
'--autodetect-root[Autodetect the root partition.]' \
23-
'--no-autodetect-root[Do not autodetect the root partition.]' \
24-
'--autodetect-root-luks[Autodetect LUKS volumes under the root partition.]' \
25-
'--no-autodetect-root-luks[Do not autodetect root LUKS volumes.]' \
26-
'--print-config[Print the final config dict.]' \
27-
'-d[Debug mode.]' \
28-
'--debug[Debug mode.]' \
29-
'--help[Show help information.]' \
30-
'-h[Show help information.]' \
31-
'-dd[Verbose debug mode.]' \
32-
'--verbose[Verbose debug mode.]' \
33-
'--log-file[Specify a log file.]' \
34-
'--log-level[Specify log level.]' \
35-
'-v[Show version information.]' \
36-
'--version[Show version information.]'
3+
# Read over each line of the output of ug --dump_args
4+
# split the line after the first space
5+
# the first part is the option, the second part is the description
6+
base_args=()
7+
while read -r line; do
8+
option=$(echo $line | cut -d' ' -f1)
9+
description=$(echo $line | cut -d' ' -f2-)
10+
base_args+=("${option}[$description]")
11+
done <<< "$(ugrd --dump_args)"
12+
13+
args=("-c[Config file location.]:config file:_files"
14+
"--config[Config file location.]:config file:_files"
15+
"--kernel-version[Set the kernel version.]:kernel version:_files -W /lib/modules -/"
16+
"--kver[Set the kernel version.]:kernel version:_files -W /lib/modules -/"
17+
"--log-file[Specify a log file.]"
18+
"--log-level[Specify log level.]")
19+
20+
args+=($base_args[@])
21+
22+
_arguments "${args[@]}"

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "ugrd"
7-
version = "1.3.4"
7+
version = "1.3.5"
88
authors = [
99
{ name="Desultory", email="[email protected]" },
1010
]
@@ -18,7 +18,7 @@ classifiers = [
1818
]
1919

2020
dependencies = [
21-
"zenlib >= 2.0.4",
21+
"zenlib >= 2.1.0",
2222
"pycpio >= 1.0.0"
2323
]
2424

readme.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ The original goal of this project was to create an initramfs suitable for decryp
3030
- Allows for late insertion of a smartcard
3131
- Can fail back to plain password entry
3232
* Auto-detection and validation of the root mount using `/proc/mounts`
33-
* Auto-detection and validation of LUKS root mounts.
34-
* Auto-detection and validation of the btrfs subvolume used for the root mount, if present.
35-
* Dynamic BTRFS subvolume selection at boot time using `subvol_selector`.
33+
* Auto-detection and validation of LUKS root mounts
34+
* Auto-detection and validation of the btrfs subvolume used for the root mount, if present
35+
* Dynamic BTRFS subvolume selection at boot time using `subvol_selector`
3636
* Auto-detection of kernel modules using `lspci` and `lsmod`
3737
* Reading the `root` and `rootflags` parameters from the kernel commandline
3838
- Falls back to host mount config if cmdline mount parameters fail
3939
* Key entry over serial
4040
* Automatic CPIO generation (PyCPIO)
41-
- Device nodes are created within the CPIO only, so true root privileges are not required.
42-
- Hardlinks are automatically created for files with matching SHA256 hashes.
41+
- Device nodes are created within the CPIO only, so true root privileges are not required
42+
- Hardlinks are automatically created for files with matching SHA256 hashes
43+
* ZSH and BASH autocompletion for the ugrd command
4344
* Similar usage/arguments as Dracut
4445

4546
### Operating system support

src/ugrd/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ def main():
1515
{'flags': ['--no-validate'], 'action': 'store_false', 'help': 'Disable config validation.', 'dest': 'validate'},
1616
{'flags': ['--hostonly'], 'action': 'store_true', 'help': 'Enable hostonly mode, required for automatic kmod detection.'},
1717
{'flags': ['--no-hostonly'], 'action': 'store_false', 'help': 'Disable hostonly mode.', 'dest': 'hostonly'},
18-
{'flags': ['--lspci'], 'action': 'store_true', 'help': 'Use lspci to auto-detect kmods', 'dest': 'kmod_autodetect_lspci'},
19-
{'flags': ['--no-lspci'], 'action': 'store_false', 'help': 'Do not use lspci to auto-detect kmods', 'dest': 'kmod_autodetect_lspci'},
20-
{'flags': ['--lsmod'], 'action': 'store_true', 'help': 'Use lsmod to auto-detect kmods', 'dest': 'kmod_autodetect_lsmod'},
21-
{'flags': ['--no-lsmod'], 'action': 'store_false', 'help': 'Do not use lsmod to auto-detect kmods', 'dest': 'kmod_autodetect_lsmod'},
18+
{'flags': ['--lspci'], 'action': 'store_true', 'help': 'Use lspci to auto-detect kmods.', 'dest': 'kmod_autodetect_lspci'},
19+
{'flags': ['--no-lspci'], 'action': 'store_false', 'help': 'Do not use lspci to auto-detect kmods.', 'dest': 'kmod_autodetect_lspci'},
20+
{'flags': ['--lsmod'], 'action': 'store_true', 'help': 'Use lsmod to auto-detect kmods.', 'dest': 'kmod_autodetect_lsmod'},
21+
{'flags': ['--no-lsmod'], 'action': 'store_false', 'help': 'Do not use lsmod to auto-detect kmods.', 'dest': 'kmod_autodetect_lsmod'},
2222
{'flags': ['--firmware'], 'action': 'store_true', 'help': 'Include firmware files found with modinfo.', 'dest': 'kmod_pull_firmware'},
2323
{'flags': ['--no-firmware'], 'action': 'store_false', 'help': 'Exclude firmware files.', 'dest': 'kmod_pull_firmware'},
2424
{'flags': ['--autodetect-root'], 'action': 'store_true', 'help': 'Autodetect the root partition.'},
2525
{'flags': ['--no-autodetect-root'], 'action': 'store_false', 'help': 'Do not autodetect the root partition.', 'dest': 'autodetect_root'},
2626
{'flags': ['--autodetect-root-luks'], 'action': 'store_true', 'help': 'Autodetect LUKS volumes under the root partition.'},
2727
{'flags': ['--no-autodetect-root-luks'], 'action': 'store_false', 'help': 'Do not autodetect root LUKS volumes.', 'dest': 'autodetect_root_luks'},
2828
{'flags': ['--print-config'], 'action': 'store_true', 'help': 'Print the final config dict.'},
29-
{'flags': ['out_file'], 'action': 'store', 'help': 'Output file location', 'nargs': '?'}]
29+
{'flags': ['out_file'], 'action': 'store', 'help': 'Output file location.', 'nargs': '?'}]
3030

3131
args, logger = get_args_n_logger(package=__package__, description='MicrogRAM disk initramfs generator', arguments=arguments, drop_default=True)
3232
kwargs = get_kwargs_from_args(args, logger=logger)

0 commit comments

Comments
 (0)