-
-
Notifications
You must be signed in to change notification settings - Fork 756
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
Tab completion support for additional archives for 'borg delete' #5655
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,32 +140,36 @@ _borg() | |
return 0 | ||
fi | ||
|
||
# Get the repository name if available | ||
# If there is a space before the "::" it means that no repository name was typed, | ||
# so probably $BORG_REPO was set and we can still list the archives. | ||
local repository_name=`expr match "${COMP_LINE}" "\(.*\)::"` | ||
repository_name=${repository_name##* } | ||
|
||
# Listing archives. | ||
# Since "::" is treated as separate word in bash, | ||
# Since "::" is treated as separate word in Bash, | ||
# it is $cur when the cursor is right behind it | ||
# and $prev if the user has started to type an archive name. | ||
local repository_name="" # If set, we'll list the archives | ||
local typed_word="" | ||
local please_list_the_archives=false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's common to use arithmetic expressions as booleans:
It's unusual to use articles in variable names. Also, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I just tried to be funny 😄 On the other hand I did come up with list_archives first, but it seemed not to express the boolean nature of the variable and it was too similar to archive_list which is a list indeed. |
||
if [[ ${cur} == "::" ]] ; then | ||
repository_name=${prev} | ||
please_list_the_archives=true | ||
fi | ||
if [[ ${prev} == "::" ]] ; then | ||
repository_name=${prevprev} | ||
please_list_the_archives=true | ||
typed_word=${cur} | ||
fi | ||
# Second archive listing for borg diff | ||
if [[ ${COMP_LINE} =~ ^.*\ diff\ .*::[^\ ]+\ ${cur}$ ]] ; then | ||
repository_name=`expr match "${COMP_LINE}" "\(.*\)::"` | ||
repository_name=${repository_name##* } | ||
please_list_the_archives=true | ||
typed_word=${cur} | ||
fi | ||
# Additional archive listing for borg delete | ||
if [[ ${COMP_LINE} =~ ^.*\ delete\ .*::[^\ ]+.*${cur}$ ]] ; then | ||
please_list_the_archives=true | ||
typed_word=${cur} | ||
fi | ||
if [[ ${repository_name} != "" ]] ; then | ||
if [[ ${COMP_LINE} == *" ::"* ]] ; then | ||
# There is a space before the "::" | ||
# which means that no repository name was typed, | ||
# so probably $BORG_REPO is set. | ||
repository_name="" | ||
fi | ||
if [[ $please_list_the_archives = true ]] ; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are going to use an arithmetic expression as boolean, than it can be done like thie:
If not, then one equal sign is inconsistent with the previous conditions (should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My goodness, that's a bug for sure, thanks for catching it. I'll fix this and also think about what you said of booleans. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a bug, just a minor inconsistency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I thought it would behave like in C as it becomes an assignment instead of comparison. |
||
local archive_list=$(borg list --short "${repository_name}" 2>/dev/null) | ||
COMPREPLY=( $(compgen -W "${archive_list}" -- "${typed_word}" ) ) | ||
return 0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to call an external command and hide its return code in order to do some matching. Can be replaced with
local repository_name="${COMP_LINE%%::*}"
. It would be better to match against the second positional argument, but I don't how to do it using bash-completion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one, thanks for that!