mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
* [ptxdist] [PATCH] Allow p link to be completed
@ 2012-09-28 15:07 Benoît Burnichon
  2012-09-30 13:02 ` Michael Olbrich
  2012-10-01 10:51 ` [ptxdist] [PATCH] Allow links " Benoît Burnichon
  0 siblings, 2 replies; 4+ messages in thread
From: Benoît Burnichon @ 2012-09-28 15:07 UTC (permalink / raw)
  To: ptxdist

using this bash_completion allows using p <Tab> to complete commands
even if ptxdist is installed on the system

Signed-off-by: Benoît Burnichon <benoit.burnichon@airtag.com>
---
 scripts/bash_completion |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/scripts/bash_completion b/scripts/bash_completion
index 3d4bc38..57d80a7 100644
--- a/scripts/bash_completion
+++ b/scripts/bash_completion
@@ -8,7 +8,13 @@ if have ptxdist; then
 
 _ptxdist_completion()
 {
-	local cur cmds opts
+	local cur cmds opts _ptxdist_cmd
+
+	if [ -h './p' ]; then
+		_ptxdist_cmd=$(readlink ./p)
+	else
+		_ptxdist_cmd=ptxdist
+	fi
 
 	COMPREPLY=()
 	cur=( $(_get_cword) )
@@ -41,13 +47,13 @@ _ptxdist_completion()
 		[ $COMP_CWORD -lt 3 ] && _filedir
 		;;
 	get|extract|prepare|compile|install|targetinstall|tags)
-		COMPREPLY=( $( compgen -W "${opts} $( ptxdist print PTX_PACKAGES_SELECTED )" -- $cur ) )
+		COMPREPLY=( $( compgen -W "${opts} $( $_ptxdist_cmd print PTX_PACKAGES_SELECTED )" -- $cur ) )
 		;;
 	clean)
-		COMPREPLY=( $( compgen -W "${opts} $( ptxdist print PTX_PACKAGES_SELECTED ) root" -- $cur ) )
+		COMPREPLY=( $( compgen -W "${opts} $( $_ptxdist_cmd print PTX_PACKAGES_SELECTED ) root" -- $cur ) )
 		;;
 	drop)
-		COMPREPLY=( $( compgen -W "${opts} $( pushd $(ptxdist print PTXDIST_PLATFORMDIR)/state >/dev/null; ls +(*.get|*.extract|*.prepare|*.compile|*.install|*.targetinstall); popd >/dev/null )" -- $cur ) )
+		COMPREPLY=( $( compgen -W "${opts} $( pushd $($_ptxdist_cmd print PTXDIST_PLATFORMDIR)/state >/dev/null; ls +(*.get|*.extract|*.prepare|*.compile|*.install|*.targetinstall); popd >/dev/null )" -- $cur ) )
 		;;
 	newpackage)
 		COMPREPLY=( $( compgen -W "${opts} target host cross klibc src-autoconf-lib src-autoconf-prog src-autoconf-proglib src-cmake-prog src-qmake-prog src-make-prog src-linux-driver src-stellaris font simple kernel image-tgz image-genimage" -- $cur) )
@@ -57,6 +63,7 @@ _ptxdist_completion()
 }
 
 complete -F _ptxdist_completion ptxdist
+complete -F _ptxdist_completion p
 
 fi
 
-- 
1.7.2.5


-- 
ptxdist mailing list
ptxdist@pengutronix.de

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

* Re: [ptxdist] [PATCH] Allow p link to be completed
  2012-09-28 15:07 [ptxdist] [PATCH] Allow p link to be completed Benoît Burnichon
@ 2012-09-30 13:02 ` Michael Olbrich
  2012-10-01 10:25   ` Benoît Burnichon
  2012-10-01 10:51 ` [ptxdist] [PATCH] Allow links " Benoît Burnichon
  1 sibling, 1 reply; 4+ messages in thread
From: Michael Olbrich @ 2012-09-30 13:02 UTC (permalink / raw)
  To: ptxdist

On Fri, Sep 28, 2012 at 05:07:53PM +0200, Benoît Burnichon wrote:
> using this bash_completion allows using p <Tab> to complete commands
> even if ptxdist is installed on the system
> 
> Signed-off-by: Benoît Burnichon <benoit.burnichon@airtag.com>
> ---
>  scripts/bash_completion |   15 +++++++++++----
>  1 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/bash_completion b/scripts/bash_completion
> index 3d4bc38..57d80a7 100644
> --- a/scripts/bash_completion
> +++ b/scripts/bash_completion
> @@ -8,7 +8,13 @@ if have ptxdist; then
>  
>  _ptxdist_completion()
>  {
> -	local cur cmds opts
> +	local cur cmds opts _ptxdist_cmd
> +
> +	if [ -h './p' ]; then
> +		_ptxdist_cmd=$(readlink ./p)
> +	else
> +		_ptxdist_cmd=ptxdist
> +	fi

	if [ "${COMP_WORDS[0]}" = "ptxdist ]; then
		_ptxdist_cmd=ptxdist
	else
		_ptxdist_cmd="$(readlink "${COMP_WORDS[0]}")"
	fi

I think. This way we're not limited to ./p
Or maybe just '_ptxdist_cmd="${COMP_WORDS[0]}"'. I'm not sure if there is
actually a case when the readlink is needed.

>  
>  	COMPREPLY=()
>  	cur=( $(_get_cword) )
> @@ -41,13 +47,13 @@ _ptxdist_completion()
>  		[ $COMP_CWORD -lt 3 ] && _filedir
>  		;;
>  	get|extract|prepare|compile|install|targetinstall|tags)
> -		COMPREPLY=( $( compgen -W "${opts} $( ptxdist print PTX_PACKAGES_SELECTED )" -- $cur ) )
> +		COMPREPLY=( $( compgen -W "${opts} $( $_ptxdist_cmd print PTX_PACKAGES_SELECTED )" -- $cur ) )
>  		;;
>  	clean)
> -		COMPREPLY=( $( compgen -W "${opts} $( ptxdist print PTX_PACKAGES_SELECTED ) root" -- $cur ) )
> +		COMPREPLY=( $( compgen -W "${opts} $( $_ptxdist_cmd print PTX_PACKAGES_SELECTED ) root" -- $cur ) )
>  		;;
>  	drop)
> -		COMPREPLY=( $( compgen -W "${opts} $( pushd $(ptxdist print PTXDIST_PLATFORMDIR)/state >/dev/null; ls +(*.get|*.extract|*.prepare|*.compile|*.install|*.targetinstall); popd >/dev/null )" -- $cur ) )
> +		COMPREPLY=( $( compgen -W "${opts} $( pushd $($_ptxdist_cmd print PTXDIST_PLATFORMDIR)/state >/dev/null; ls +(*.get|*.extract|*.prepare|*.compile|*.install|*.targetinstall); popd >/dev/null )" -- $cur ) )
>  		;;
>  	newpackage)
>  		COMPREPLY=( $( compgen -W "${opts} target host cross klibc src-autoconf-lib src-autoconf-prog src-autoconf-proglib src-cmake-prog src-qmake-prog src-make-prog src-linux-driver src-stellaris font simple kernel image-tgz image-genimage" -- $cur) )
> @@ -57,6 +63,7 @@ _ptxdist_completion()
>  }
>  
>  complete -F _ptxdist_completion ptxdist
> +complete -F _ptxdist_completion p

I'm not sure if this last change is a good idea by default. 'p' is rather
ambiguous. But if we merge the rest, then it's easy to add just this line
to ~/.bash_completion

michael

>  
>  fi
>  
> -- 
> 1.7.2.5
> 
> 
> -- 
> ptxdist mailing list
> ptxdist@pengutronix.de

-- 
ptxdist mailing list
ptxdist@pengutronix.de

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

* Re: [ptxdist] [PATCH] Allow p link to be completed
  2012-09-30 13:02 ` Michael Olbrich
@ 2012-10-01 10:25   ` Benoît Burnichon
  0 siblings, 0 replies; 4+ messages in thread
From: Benoît Burnichon @ 2012-10-01 10:25 UTC (permalink / raw)
  To: ptxdist

[-- Attachment #1: Type: text/plain, Size: 1431 bytes --]


On Sun, 30 Sep 2012, Michael Olbrich wrote:

> On Fri, Sep 28, 2012 at 05:07:53PM +0200, Benoît Burnichon wrote:
>>  _ptxdist_completion()
>>  {
>> -	local cur cmds opts
>> +	local cur cmds opts _ptxdist_cmd
>> +
>> +	if [ -h './p' ]; then
>> +		_ptxdist_cmd=$(readlink ./p)
>> +	else
>> +		_ptxdist_cmd=ptxdist
>> +	fi
>
> 	if [ "${COMP_WORDS[0]}" = "ptxdist ]; then
> 		_ptxdist_cmd=ptxdist
> 	else
> 		_ptxdist_cmd="$(readlink "${COMP_WORDS[0]}")"
> 	fi
>
> I think. This way we're not limited to ./p
> Or maybe just '_ptxdist_cmd="${COMP_WORDS[0]}"'. I'm not sure if there is
> actually a case when the readlink is needed.
>

Fine with removing limitation to only ./p

Kept the readlink command as there is a case where it does not work.

Suppose you are only type p in your project directory then press <Tab>, 
there will be an issue because the called ptxdist will be p in the current 
directory and bash will not find the ptxdist script as it is not in the 
current directory

>>  complete -F _ptxdist_completion ptxdist
>> +complete -F _ptxdist_completion p
>
> I'm not sure if this last change is a good idea by default. 'p' is rather
> ambiguous. But if we merge the rest, then it's easy to add just this line
> to ~/.bash_completion
>

You're probably right, this is not good idea. Let the users configures 
their own bash_completion to whatever name they choose.

Benoît

[-- Attachment #2: Type: text/plain, Size: 48 bytes --]

-- 
ptxdist mailing list
ptxdist@pengutronix.de

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

* [ptxdist] [PATCH] Allow links to be completed
  2012-09-28 15:07 [ptxdist] [PATCH] Allow p link to be completed Benoît Burnichon
  2012-09-30 13:02 ` Michael Olbrich
@ 2012-10-01 10:51 ` Benoît Burnichon
  1 sibling, 0 replies; 4+ messages in thread
From: Benoît Burnichon @ 2012-10-01 10:51 UTC (permalink / raw)
  To: ptxdist

using this bash_completion allows using p <Tab> to complete commands
even if ptxdist is installed on the system

Signed-off-by: Benoît Burnichon <benoit.burnichon@airtag.com>
---
 scripts/bash_completion |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/scripts/bash_completion b/scripts/bash_completion
index 3d4bc38..2a51276 100644
--- a/scripts/bash_completion
+++ b/scripts/bash_completion
@@ -8,7 +8,13 @@ if have ptxdist; then
 
 _ptxdist_completion()
 {
-	local cur cmds opts
+	local cur cmds opts _ptxdist_cmd
+
+	if [ "${COMP_WORDS[0]}" = "ptxdist" ]; then
+		_ptxdist_cmd="ptxdist"
+	else
+		_ptxdist_cmd="${COMP_WORDS[0]}"
+	fi
 
 	COMPREPLY=()
 	cur=( $(_get_cword) )
@@ -41,13 +47,13 @@ _ptxdist_completion()
 		[ $COMP_CWORD -lt 3 ] && _filedir
 		;;
 	get|extract|prepare|compile|install|targetinstall|tags)
-		COMPREPLY=( $( compgen -W "${opts} $( ptxdist print PTX_PACKAGES_SELECTED )" -- $cur ) )
+		COMPREPLY=( $( compgen -W "${opts} $( $_ptxdist_cmd print PTX_PACKAGES_SELECTED )" -- $cur ) )
 		;;
 	clean)
-		COMPREPLY=( $( compgen -W "${opts} $( ptxdist print PTX_PACKAGES_SELECTED ) root" -- $cur ) )
+		COMPREPLY=( $( compgen -W "${opts} $( $_ptxdist_cmd print PTX_PACKAGES_SELECTED ) root" -- $cur ) )
 		;;
 	drop)
-		COMPREPLY=( $( compgen -W "${opts} $( pushd $(ptxdist print PTXDIST_PLATFORMDIR)/state >/dev/null; ls +(*.get|*.extract|*.prepare|*.compile|*.install|*.targetinstall); popd >/dev/null )" -- $cur ) )
+		COMPREPLY=( $( compgen -W "${opts} $( pushd $($_ptxdist_cmd print PTXDIST_PLATFORMDIR)/state >/dev/null; ls +(*.get|*.extract|*.prepare|*.compile|*.install|*.targetinstall); popd >/dev/null )" -- $cur ) )
 		;;
 	newpackage)
 		COMPREPLY=( $( compgen -W "${opts} target host cross klibc src-autoconf-lib src-autoconf-prog src-autoconf-proglib src-cmake-prog src-qmake-prog src-make-prog src-linux-driver src-stellaris font simple kernel image-tgz image-genimage" -- $cur) )
-- 
1.7.2.5


-- 
ptxdist mailing list
ptxdist@pengutronix.de

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

end of thread, other threads:[~2012-10-01 10:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-28 15:07 [ptxdist] [PATCH] Allow p link to be completed Benoît Burnichon
2012-09-30 13:02 ` Michael Olbrich
2012-10-01 10:25   ` Benoît Burnichon
2012-10-01 10:51 ` [ptxdist] [PATCH] Allow links " Benoît Burnichon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox