[darcs-devel] [patch2123] bash_completion: do not use provided options when invo...

Gian Piero Carrubba bugs at darcs.net
Wed Dec 23 12:03:59 UTC 2020


Gian Piero Carrubba <gpiero at rm-rf.it> added the comment:

Amended patch.

Tangentially, in src/Darcs/UI/Commands/Record.hs:255:

checkNameIsNotOption (Just name) True   =
     when (length name == 1 || (length name == 2 && head name == '-')) $ do
         confirmed <- promptYorn $ "You specified " ++ show name ++ " as the patch name. Is that really what you want?"
         unless confirmed $ putStrLn "Okay, aborting the record." >> exitFailure

Would it be sensible to check for a patch name starting with '-' without 
the length constraint?
Or maybe better:
length name == 1 ||
(length == 2 && head name == '-') ||
(length > 2 && take 2 name == "--" && isAlpha/isAlphaNum (name!!2))

I don't like to be burdened with useless prompts, but maybe sometimes 
they make sense...

__________________________________
Darcs bug tracker <bugs at darcs.net>
<http://bugs.darcs.net/patch2123>
__________________________________
-------------- next part --------------
1 patch for repository http://darcs.net:

patch 24f5930d6c2958a01462ecbda10bbdadf0e7c90c
Author: Gian Piero Carrubba <gpiero at rm-rf.it>
Date:   Tue Dec 22 12:45:05 CET 2020
  * bash_completion: use '--list-options' before any other option
  
  This is so to avoid that, e.g.:
  
  $ darcs record -m <Tab><Tab>
  
  results in a patch named '--list-options' being recorded.


New patches:

[bash_completion: use '--list-options' before any other option
Gian Piero Carrubba <gpiero at rm-rf.it>**20201222114505
 Ignore-this: 3846b35e4c2bfe4e2af2fb5d9120e8686232309864ccf602dd32ad4b34d498f64c81f8beebb0fb1f
 
 This is so to avoid that, e.g.:
 
 $ darcs record -m <Tab><Tab>
 
 results in a patch named '--list-options' being recorded.
] hunk ./contrib/darcs_completion 19
-    # Store the whole command line substituting the (possibly empty)
-    # to-be-completed word with '--list-options'.
-    local -a words=("${COMP_WORDS[@]}")
-    words[$COMP_CWORD]="--list-options"
+    # Top-level options do not accept any further options
+    case "${COMP_WORDS[1]}" in
+        (-*) COMPREPLY=''; return 0;;
+    esac
hunk ./contrib/darcs_completion 24
-    # Options are processed from left to right, so avoid to display the help
-    # page when trying to complete a command line that includes '--help'. It
-    # could be tricked by things like '--repodir --hell', but, come on... you
-    # don't deserve a working completion if you name a directory '--hell'.
-    for w in "${words[@]}"; do
-        case "$w" in
-            (--he*) return 0;;
+    # Build a new command line copying all the tokens and inserting
+    # '--list-options' before the first option (a token starting with '-').
+    local -a cmdline
+    local i=0
+    local m=$(( ${#COMP_WORDS[@]} - 1 ))
+    for token in "${COMP_WORDS[@]:0:${m}}"
+    do
+        case "$token" in
+            (-*) cmdline+=("--list-options" "${COMP_WORDS[@]:${i}}");
+                 break;;
+             (*) cmdline+=("$token");
+                 i=$(( $i + 1 ));;
hunk ./contrib/darcs_completion 38
+    test $i -eq $m && cmdline+=("--list-options")
hunk ./contrib/darcs_completion 43
-    COMPREPLY=( $( "${words[@]}" 2>/dev/null |\
+    COMPREPLY=( $( "${cmdline[@]}" 2>/dev/null |\
hunk ./contrib/darcs_completion 46
-	# Then, we adapt the resulting strings to be reusable by bash. If we don't
-	# do this, in the case where we have two repositories named
-	# ~/space in there-0.1 and ~/space in there-0.2, the first completion will
-	# give us:
-	# bash> darcs push ~/space in there-0.
-	# ~/space in there-0.1 ~/space in there-0.2
-	# and we have introduced two spaces in the command line (if we try to
-	# recomplete that, it won't find anything, as it doesn't know anything
-	# starting with "there-0.").
-	# printf %q will gracefully add the necessary backslashes.
-	#
-	# Bash also interprets colon as a separator. If we didn't handle it
-	# specially, completing http://example.org/repo from http://e would 
-	# give us:
-	# bash> darcs pull http:http://example.org/repo
-	# An option would be to require the user to escape : as \: and we
-	# would do the same here. Instead, we return only the part after
-	# the last colon that is already there, and thus fool bash. The
-	# downside is that bash only shows this part to the user.
+    # Then, we adapt the resulting strings to be reusable by bash. If we don't
+    # do this, in the case where we have two repositories named
+    # ~/space in there-0.1 and ~/space in there-0.2, the first completion will
+    # give us:
+    # bash> darcs push ~/space in there-0.
+    # ~/space in there-0.1 ~/space in there-0.2
+    # and we have introduced two spaces in the command line (if we try to
+    # recomplete that, it won't find anything, as it doesn't know anything
+    # starting with "there-0.").
+    # printf %q will gracefully add the necessary backslashes.
+    #
+    # Bash also interprets colon as a separator. If we didn't handle it
+    # specially, completing http://example.org/repo from http://e would
+    # give us:
+    # bash> darcs pull http:http://example.org/repo
+    # An option would be to require the user to escape : as \: and we
+    # would do the same here. Instead, we return only the part after
+    # the last colon that is already there, and thus fool bash. The
+    # downside is that bash only shows this part to the user.
hunk ./contrib/darcs_completion 69
-      COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} 
+      COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"}

Context:

[TAG 2.16.1
Ben Franksen <ben.franksen at online.de>**20200814093257
 Ignore-this: b5957de98ad629b97483fd6bee8941e2871a58aac4c559d37921feda3e88f06c5a939f40820abf9f
] 
Patch bundle hash:
6f80b4b782b5e3adf3855c279fc08a90893035d2


More information about the darcs-devel mailing list