From 5b656d3d67dfa9f9140e0f7fbdc4a0d0aa76ef6c Mon Sep 17 00:00:00 2001 From: sd Date: Wed, 4 May 2022 14:44:06 +0300 Subject: [PATCH 1/5] Add more module dirs to kldload --- completions/kldload | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/completions/kldload b/completions/kldload index f5111584c0b..b884ba2ccd9 100644 --- a/completions/kldload +++ b/completions/kldload @@ -7,12 +7,16 @@ _kldload() local cur prev words cword _init_completion || return - local moddir=/modules/ - [[ -d $moddir ]] || moddir=/boot/kernel/ + local moddirs modules i + IFS=';' read -ra moddirs <<< "$(sysctl -n kern.module_path)" compopt -o filenames - COMPREPLY=($(compgen -f "$moddir$cur")) - COMPREPLY=(${COMPREPLY[@]#$moddir}) + COMPREPLY=() + for i in "${moddirs[@]}"; do + modules=($(compgen -f "$i/$cur")) + modules=(${modules[@]#$i/}) + COMPREPLY=("${COMPREPLY[@]}" "${modules[@]}") + done COMPREPLY=(${COMPREPLY[@]%.ko}) } && From 8bdedc1af4d0addd5cc7070d48776589612349cd Mon Sep 17 00:00:00 2001 From: Dystopian Date: Mon, 30 May 2022 09:46:08 +0400 Subject: [PATCH 2/5] Avoid herestrings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ville Skyttä --- completions/kldload | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/completions/kldload b/completions/kldload index b884ba2ccd9..c40cfc07a42 100644 --- a/completions/kldload +++ b/completions/kldload @@ -7,8 +7,9 @@ _kldload() local cur prev words cword _init_completion || return - local moddirs modules i - IFS=';' read -ra moddirs <<< "$(sysctl -n kern.module_path)" + local moddirs modules i IFS=";" + moddirs=($(sysctl -n kern.module_path)) + _comp_unlocal IFS compopt -o filenames COMPREPLY=() From e3d98b7fde0199ffcb9f0d2a364f83eef1caaa37 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Mon, 30 May 2022 09:58:30 +0400 Subject: [PATCH 3/5] Optimize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ville Skyttä --- completions/kldload | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/completions/kldload b/completions/kldload index c40cfc07a42..2acff559b90 100644 --- a/completions/kldload +++ b/completions/kldload @@ -12,11 +12,10 @@ _kldload() _comp_unlocal IFS compopt -o filenames - COMPREPLY=() for i in "${moddirs[@]}"; do modules=($(compgen -f "$i/$cur")) modules=(${modules[@]#$i/}) - COMPREPLY=("${COMPREPLY[@]}" "${modules[@]}") + COMPREPLY+=("${modules[@]}") done COMPREPLY=(${COMPREPLY[@]%.ko}) From c252f931c00a4b5335e5cb234e21ec96d16ea839 Mon Sep 17 00:00:00 2001 From: sd Date: Mon, 30 May 2022 10:51:59 +0300 Subject: [PATCH 4/5] Use kldconfig instead of sysctl --- completions/kldload | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/kldload b/completions/kldload index 2acff559b90..34e12c124ec 100644 --- a/completions/kldload +++ b/completions/kldload @@ -8,7 +8,7 @@ _kldload() _init_completion || return local moddirs modules i IFS=";" - moddirs=($(sysctl -n kern.module_path)) + moddirs=($(kldconfig -r 2>/dev/null)) _comp_unlocal IFS compopt -o filenames From 4118a1a43310ec0650ac34932f4e62a8628a101e Mon Sep 17 00:00:00 2001 From: sd Date: Mon, 30 May 2022 11:36:41 +0300 Subject: [PATCH 5/5] Add dirs to list --- completions/kldload | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/completions/kldload b/completions/kldload index 34e12c124ec..3cce9423fc7 100644 --- a/completions/kldload +++ b/completions/kldload @@ -7,6 +7,11 @@ _kldload() local cur prev words cword _init_completion || return + if [[ "$cur" == */* ]]; then + _filedir ko + return + fi + local moddirs modules i IFS=";" moddirs=($(kldconfig -r 2>/dev/null)) _comp_unlocal IFS @@ -19,6 +24,9 @@ _kldload() done COMPREPLY=(${COMPREPLY[@]%.ko}) + # also add dirs in current dir + _filedir -d + } && complete -F _kldload kldload