zsh-workers
 help / color / mirror / code / Atom feed
* [RFC PATCH 1/2] complete absolute paths for mpc add
@ 2024-09-27 16:31 Karel Balej
  2024-09-27 16:31 ` [RFC PATCH 2/2] enable completion for mpc insert Karel Balej
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Karel Balej @ 2024-09-27 16:31 UTC (permalink / raw)
  To: zsh-workers; +Cc: balejk

When connecting via Unix socket, mpc can queue files from outside the
music directory as well when given the absolute path.
---
mpc also supports explicitly prefixing the path with file:// which is
not covered here, however according to my testing this only works for
absolute paths too so there doesn't seem to be any benefit.

This implementation doesn't work with environment variables, such as
mpc add $HOME/somethi<tab>, I will appreciate tips on whether there is a
simple way to make this more robust to include situations such as this
instead of just checking for these two specific starting characters.

Thank you and kind regards,
K. B.

 Completion/Unix/Command/_mpc | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_mpc b/Completion/Unix/Command/_mpc
index c3f93878ca28..93100de09ca8 100644
--- a/Completion/Unix/Command/_mpc
+++ b/Completion/Unix/Command/_mpc
@@ -178,6 +178,14 @@ _mpc_helper_files() {
   fi
 }
 
+(( $+functions[_mpc_helper_all_files] )) ||
+_mpc_helper_all_files() {
+  if [[ $words[CURRENT] == [/~]* ]]; then
+	  _files
+  fi
+  _mpc_helper_files
+}
+
 (( $+functions[_mpc_helper_directories] )) ||
 _mpc_helper_directories() {
   if [[ -n $MPD_MUSIC_DIR ]]; then
@@ -204,7 +212,7 @@ _mpc_helper_outputs() {
 }
 
 _mpc_add() {
-  _mpc_helper_files
+  _mpc_helper_all_files
 }
 
 _mpc_albumart() {
-- 
2.46.0



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RFC PATCH 2/2] enable completion for mpc insert
  2024-09-27 16:31 [RFC PATCH 1/2] complete absolute paths for mpc add Karel Balej
@ 2024-09-27 16:31 ` Karel Balej
  2024-11-09 15:21 ` [RFC PATCH 1/2] complete absolute paths for mpc add Karel Balej
  2024-11-09 19:44 ` Bart Schaefer
  2 siblings, 0 replies; 8+ messages in thread
From: Karel Balej @ 2024-09-27 16:31 UTC (permalink / raw)
  To: zsh-workers; +Cc: balejk

---
 Completion/Unix/Command/_mpc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Completion/Unix/Command/_mpc b/Completion/Unix/Command/_mpc
index 93100de09ca8..4566866ebfbd 100644
--- a/Completion/Unix/Command/_mpc
+++ b/Completion/Unix/Command/_mpc
@@ -215,6 +215,10 @@ _mpc_add() {
   _mpc_helper_all_files
 }
 
+_mpc_insert() {
+  _mpc_helper_all_files
+}
+
 _mpc_albumart() {
   _mpc_helper_files
 }
-- 
2.46.0



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/2] complete absolute paths for mpc add
  2024-09-27 16:31 [RFC PATCH 1/2] complete absolute paths for mpc add Karel Balej
  2024-09-27 16:31 ` [RFC PATCH 2/2] enable completion for mpc insert Karel Balej
@ 2024-11-09 15:21 ` Karel Balej
  2024-11-09 19:44 ` Bart Schaefer
  2 siblings, 0 replies; 8+ messages in thread
From: Karel Balej @ 2024-11-09 15:21 UTC (permalink / raw)
  To: zsh-workers

Hello,

Karel Balej, 2024-09-27T18:31:34+02:00:
> When connecting via Unix socket, mpc can queue files from outside the
> music directory as well when given the absolute path.
> ---
> mpc also supports explicitly prefixing the path with file:// which is
> not covered here, however according to my testing this only works for
> absolute paths too so there doesn't seem to be any benefit.
>
> This implementation doesn't work with environment variables, such as
> mpc add $HOME/somethi<tab>, I will appreciate tips on whether there is a
> simple way to make this more robust to include situations such as this
> instead of just checking for these two specific starting characters.

could I please get some feedback on these two patches?

Thank you,
K. B.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/2] complete absolute paths for mpc add
  2024-09-27 16:31 [RFC PATCH 1/2] complete absolute paths for mpc add Karel Balej
  2024-09-27 16:31 ` [RFC PATCH 2/2] enable completion for mpc insert Karel Balej
  2024-11-09 15:21 ` [RFC PATCH 1/2] complete absolute paths for mpc add Karel Balej
@ 2024-11-09 19:44 ` Bart Schaefer
  2024-11-10 18:56   ` Karel Balej
  2 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2024-11-09 19:44 UTC (permalink / raw)
  To: Karel Balej; +Cc: zsh-workers

I didn't see this the first time around for some reason.

On Fri, Sep 27, 2024 at 9:34 AM Karel Balej <balejk@matfyz.cz> wrote:
>
> +(( $+functions[_mpc_helper_all_files] )) ||
> +_mpc_helper_all_files() {
> +  if [[ $words[CURRENT] == [/~]* ]]; then
> +         _files
> +  fi
> +  _mpc_helper_files
> +}

If _files succeeds ($? == 0) but _mpc_helper_files fails ($? != 0)
then _mpc_helper_all_files will appear to fail and completion will
proceed to the next possible alternative.

Does something like the following still give the result you expect?

_mpc_helper_all_files() {
  local ret=1
  if [[ $words[CURRENT] == [/~]* ]]; then
         _files
         ret=$?
  fi
  _mpc_helper_files || return ret
}


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/2] complete absolute paths for mpc add
  2024-11-09 19:44 ` Bart Schaefer
@ 2024-11-10 18:56   ` Karel Balej
  2024-11-10 23:10     ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Karel Balej @ 2024-11-10 18:56 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

Bart Schaefer, 2024-11-09T11:44:08-08:00:
> I didn't see this the first time around for some reason.
>
> On Fri, Sep 27, 2024 at 9:34 AM Karel Balej <balejk@matfyz.cz> wrote:
> >
> > +(( $+functions[_mpc_helper_all_files] )) ||
> > +_mpc_helper_all_files() {
> > +  if [[ $words[CURRENT] == [/~]* ]]; then
> > +         _files
> > +  fi
> > +  _mpc_helper_files
> > +}
>
> If _files succeeds ($? == 0) but _mpc_helper_files fails ($? != 0)
> then _mpc_helper_all_files will appear to fail and completion will
> proceed to the next possible alternative.
>
> Does something like the following still give the result you expect?
>
> _mpc_helper_all_files() {
>   local ret=1
>   if [[ $words[CURRENT] == [/~]* ]]; then
>          _files
>          ret=$?
>   fi
>   _mpc_helper_files || return ret
> }

Thank you, this seems to give me the same results as the original,
however I don't immediately see any difference in behaviour even when I
force _mpc_helper_files to fail -- the _files results are still
completed even without the ret handling. Or do I just misunderstand how
this should work?

Again, I might misunderstand how this "next possible alternative"
mechanism works, however it occurred to me whether it might be possible
and possibly simpler to just have _mpc_helper_files fail on no matches
and have the completion fall back to _files only then?

Best regards,
K. B.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/2] complete absolute paths for mpc add
  2024-11-10 18:56   ` Karel Balej
@ 2024-11-10 23:10     ` Bart Schaefer
  2024-11-11 19:26       ` Karel Balej
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2024-11-10 23:10 UTC (permalink / raw)
  To: Karel Balej; +Cc: zsh-workers

On Sun, Nov 10, 2024 at 10:56 AM Karel Balej <balejk@matfyz.cz> wrote:
>
> Thank you, this seems to give me the same results as the original,
> however I don't immediately see any difference in behaviour even when I
> force _mpc_helper_files to fail -- the _files results are still
> completed even without the ret handling. Or do I just misunderstand how
> this should work?

You won't get any fewer completions -- all those added by _files will
still be valid -- but if there is another (perhaps less specific)
possible completer after _mpc_helper_files fails, then additional
possible matches from that other completer will also be added.  In
ordinary circumstances, completion stops after a completer returns
success, unless specially programmed to continue.

>... possibly simpler to just have _mpc_helper_files fail on no matches
> and have the completion fall back to _files only then?

If, when _mpc_helper_files does find something, you don't mind
skipping files that _mpc_helper_files does not find, you can certainly
do that.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/2] complete absolute paths for mpc add
  2024-11-10 23:10     ` Bart Schaefer
@ 2024-11-11 19:26       ` Karel Balej
  2024-11-12  2:52         ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Karel Balej @ 2024-11-11 19:26 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

Bart Schaefer, 2024-11-10T15:10:55-08:00:
> On Sun, Nov 10, 2024 at 10:56 AM Karel Balej <balejk@matfyz.cz> wrote:
> >... possibly simpler to just have _mpc_helper_files fail on no matches
> > and have the completion fall back to _files only then?
>
> If, when _mpc_helper_files does find something, you don't mind
> skipping files that _mpc_helper_files does not find, you can certainly
> do that.

Actually that isn't really better because only absolute paths should be
completed via _files.

So if you have no further comments, I can submit the original patches
updated with the ret handling.

Thank you,
K. B.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/2] complete absolute paths for mpc add
  2024-11-11 19:26       ` Karel Balej
@ 2024-11-12  2:52         ` Bart Schaefer
  0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2024-11-12  2:52 UTC (permalink / raw)
  To: Karel Balej; +Cc: zsh-workers

I have no further comments.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-11-12  2:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-27 16:31 [RFC PATCH 1/2] complete absolute paths for mpc add Karel Balej
2024-09-27 16:31 ` [RFC PATCH 2/2] enable completion for mpc insert Karel Balej
2024-11-09 15:21 ` [RFC PATCH 1/2] complete absolute paths for mpc add Karel Balej
2024-11-09 19:44 ` Bart Schaefer
2024-11-10 18:56   ` Karel Balej
2024-11-10 23:10     ` Bart Schaefer
2024-11-11 19:26       ` Karel Balej
2024-11-12  2:52         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).