-
Notifications
You must be signed in to change notification settings - Fork 78
Add shell completion for mkdwarfs (bash, zsh) #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
# SPDX-License-Identifier: MIT | ||
# Author: Ahmad Khalifa | ||
# | ||
# bash completion for mkdwarfs | ||
# | ||
# synopsis | ||
# mkdwarfs [OPTIONS...] | ||
# | ||
|
||
# TODO: unreliable? maybe not if app keeps the two groups intact. | ||
__mkdwarfs_list_comp_algos() | ||
{ | ||
# extract algorithms block | ||
# trim algo leading space, delete algo args, remove empty line | ||
# delete algo descriptions | ||
# double print with trailing ':' except 'null' - they complete with no space | ||
mkdwarfs -H | \ | ||
sed -e '1,/Compression algorithms/d;/Categories:/,$d' \ | ||
-e 's/^[ ]\{1,2\}//;/^ /d;/^$/d' \ | ||
-e 's/ .*$//' \ | ||
-ne 'p;/null/!s/$/:/p' | ||
} | ||
|
||
__mkdwarfs_additional_options() | ||
{ | ||
if [[ "$(mkdwarfs -h | grep -e ' *--man')" ]]; then | ||
echo "--man" | ||
fi | ||
} | ||
|
||
_mkdwarfs_completion() | ||
{ | ||
local cur prev words cword | ||
_comp_initialize || return | ||
|
||
local OPTIONS_GENERAL=( | ||
--bloom-filter-size | ||
--categorize | ||
--change-block-size | ||
--chmod | ||
--compress-niceness | ||
--debug-filter | ||
--file-hash | ||
--header | ||
--history-compression | ||
--hotness-list | ||
--incompressible-block-size | ||
--incompressible-fragments | ||
--incompressible-min-input-size | ||
--incompressible-ratio | ||
--incompressible-zstd-level | ||
--input-list | ||
--keep-all-times | ||
--log-level | ||
--log-with-context | ||
--man | ||
--max-similarity-size | ||
--metadata-compression | ||
--no-category-metadata | ||
--no-category-names | ||
--no-create-timestamp | ||
--no-history | ||
--no-history-command-line | ||
--no-history-timestamps | ||
--no-metadata-version-history | ||
--no-progress | ||
--no-section-index | ||
--num-scanner-workers | ||
--num-segmenter-workers | ||
--order | ||
--progress | ||
--rebuild-metadata | ||
--recompress | ||
--recompress-categories | ||
--remove-empty-dirs | ||
--remove-header | ||
--schema-compression | ||
--set-group | ||
--set-owner | ||
--set-time | ||
--time-resolution | ||
--with-devices | ||
--with-specials | ||
-B --max-lookback-blocks | ||
-C --compression | ||
-F --filter | ||
-f --force | ||
-h --help | ||
-H --long-help | ||
-i --input | ||
-l --compress-level | ||
-L --memory-limit | ||
-N --num-workers | ||
-o --output | ||
-P --pack-metadata | ||
-S --block-size-bits | ||
-W --window-size | ||
-w --window-step | ||
$(__mkdwarfs_additional_options) | ||
) | ||
|
||
local OPTION_ARG__log_level=( error warn info verbose debug trace ) | ||
local OPTION_ARG__compress_level=( 0 1 2 3 4 5 6 7 8 9 ) | ||
local OPTION_ARG__recompress=( none block metadata all ) | ||
local OPTION_ARG__categorize=( fits pcmaudio incompressible ) | ||
# TODO: find a better way to extract these at runtime | ||
local OPTION_ARG__file_hash=( ) | ||
local OPTION_ARG__progress=( ascii none simple unicode ) | ||
local OPTION_ARG__pack_metadata=( auto all none chunk_table directories | ||
shared_files names names_index symlinks symlinks_index force plain ) | ||
|
||
# catch option with known arguments first | ||
case $prev in | ||
--log-level | --compress-level | --recompress | \ | ||
--categorize | --file-hash | --progress | --pack-metadata) | ||
prevoption=${prev//-/_} | ||
_comp_compgen -- -W '"${OPTION_ARG'$prevoption'[@]}"' | ||
return 0 | ||
;; | ||
-P) | ||
_comp_compgen -- -W '"${OPTION_ARG__pack_metadata[@]}"' | ||
return 0 | ||
;; | ||
-l) | ||
_comp_compgen -- -W '"${OPTION_ARG__compress_level[@]}"' | ||
return 0 | ||
;; | ||
--set-owner) | ||
_comp_compgen -- uids | ||
return 0 | ||
;; | ||
--set-group) | ||
_comp_compgen -- gids | ||
return 0 | ||
;; | ||
-i | --input) | ||
_comp_compgen -a filedir -d | ||
return 0 | ||
;; | ||
--input-list | -o | --output) | ||
_comp_compgen -a filedir | ||
return 0 | ||
;; | ||
--compression | --schema-compression | \ | ||
--metadata-compression | --history-compression) | ||
# TODO: complete algo args based $prev and ':' or ',' | ||
# --prev <algo>:<arg1>=<_>,<arg2>=<_> | ||
_comp_compgen -- -W '$(__mkdwarfs_list_comp_algos)' | ||
return 0 | ||
;; | ||
esac | ||
|
||
|
||
if [[ $cur == -* ]]; then | ||
# cursor on an option, show options only | ||
_comp_compgen -- -W '"${OPTIONS_GENERAL[@]}"' | ||
else | ||
# show all options and files | ||
_comp_compgen -- -W '"${OPTIONS_GENERAL[@]}"' | ||
_comp_compgen -a filedir | ||
fi | ||
|
||
return 0 | ||
} && | ||
complete -F _mkdwarfs_completion mkdwarfs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#compdef mkdwarfs | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# Author: Ahmad Khalifa | ||
# | ||
# zsh completion for mkdwarfs | ||
# | ||
# synopsis | ||
# mkdwarfs [OPTIONS...] | ||
# | ||
|
||
local context state line ret=1 | ||
|
||
# TODO: unreliable? maybe not if app keeps the two groups intact. | ||
__mkdwarfs_list_comp_algos() | ||
{ | ||
# extract algorithms block | ||
# trim algo leading space, delete algo args, remove empty line | ||
# delete algo descriptions | ||
# double print with trailing '\:' except 'null' | ||
mkdwarfs -H | \ | ||
sed -e '1,/Compression algorithms/d;/Categories:/,$d' \ | ||
-e 's/^[ ]\{1,2\}//;/^ /d;/^$/d' \ | ||
-e 's/ .*$//' \ | ||
-ne 'p;/null/!s/$/\\:/p' | ||
} | ||
|
||
__mkdwarfs_disable_man() | ||
{ | ||
if [[ ! "$(mkdwarfs -h | grep -e ' *--man')" ]]; then | ||
echo -n "!" | ||
fi | ||
} | ||
|
||
_arguments -S \ | ||
"--bloom-filter-size" \ | ||
"--categorize=-:cattype:_values -s , cattype fits pcmaudio incompressible" \ | ||
"--change-block-size" \ | ||
"--chmod" \ | ||
"--compress-niceness" \ | ||
"--debug-filter" \ | ||
"--file-hash:hashfnc:" \ | ||
"--header" \ | ||
"--history-compression:algos:($(__mkdwarfs_list_comp_algos))" \ | ||
"--hotness-list" \ | ||
"--incompressible-block-size" \ | ||
"--incompressible-fragments" \ | ||
"--incompressible-min-input-size" \ | ||
"--incompressible-ratio" \ | ||
"--incompressible-zstd-level" \ | ||
"--input-list[file containing list of file paths relative to root directory or - for stdin]:filename:_files" \ | ||
"--keep-all-times[save atime and ctime in addition to mtime]" \ | ||
"--log-level:level:(error warn info verbose debug trace)" \ | ||
"--log-with-context" \ | ||
"--max-similarity-size" \ | ||
"--metadata-compression:algos:($(__mkdwarfs_list_comp_algos))" \ | ||
"--no-category-metadata" \ | ||
"--no-category-names" \ | ||
"--no-create-timestamp" \ | ||
"--no-history" \ | ||
"--no-history-command-line" \ | ||
"--no-history-timestamps" \ | ||
"--no-metadata-version-history" \ | ||
"--no-progress" \ | ||
"--no-section-index" \ | ||
"--num-scanner-workers" \ | ||
"--num-segmenter-workers" \ | ||
"--order" \ | ||
"--progress:progress:(ascii none simple unicode)" \ | ||
"--rebuild-metadata" \ | ||
"--recompress:level:(none block metadata all)" \ | ||
"--recompress-categories" \ | ||
"--remove-empty-dirs" \ | ||
"--remove-header" \ | ||
"--schema-compression:algos:($(__mkdwarfs_list_comp_algos))" \ | ||
"--set-group[group (gid) for whole file system]" \ | ||
"--set-owner[owner (uid) for whole file system]" \ | ||
"--set-time[timestamp for whole file system (unixtime or 'now')]" \ | ||
"--time-resolution" \ | ||
"--with-devices" \ | ||
"--with-specials" \ | ||
{-B,--max-lookback-blocks} \ | ||
{-C,--compression=-}"[block compression algorithm]:algos:($(__mkdwarfs_list_comp_algos))" \ | ||
{-F,--filter} \ | ||
{-f,--force}"[force overwrite of existing output image]" \ | ||
{-h,--help}"[help message]" \ | ||
{-H,--long-help}"[full help message]" \ | ||
{-i,--input}"[path to root directory or source filesystem]:directory:_files -/" \ | ||
{-l,--compress-level}"[compression level (0=fast, 9=best)]:level:(0 1 2 3 4 5 6 7 8 9)" \ | ||
{-L,--memory-limit} \ | ||
{-N,--num-workers}"[number of writer (compression) worker threads]" \ | ||
{-o,--output}"[filesystem output name or - for stdout]:filename:_files" \ | ||
{-P,--pack-metadata}":packtype:_values packtype auto all none \ | ||
chunk_table directories shared_files names names_index symlinks \ | ||
symlinks_index force plain" \ | ||
{-S,--block-size-bits} \ | ||
{-W,--window-size} \ | ||
{-w,--window-step} \ | ||
"$(__mkdwarfs_disable_man)--man[show manual page and exit]" && ret=0 | ||
|
||
return ret |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.