[Bash-completion-commits] ./current r1237: Improved filename based man page completion.

Ville Skyttä ville.skytta at iki.fi
Sun Jan 11 22:23:32 UTC 2009


------------------------------------------------------------
revno: 1237
committer: Ville Skyttä <ville.skytta at iki.fi>
branch nick: current
timestamp: Mon 2009-01-12 00:23:32 +0200
message:
  Improved filename based man page completion.
modified:
  bash_completion
  debian/changelog
-------------- next part --------------
=== modified file 'bash_completion'
--- a/bash_completion	2009-01-11 22:10:22 +0000
+++ b/bash_completion	2009-01-11 22:23:32 +0000
@@ -848,7 +848,9 @@
   -o $UNAME = OpenBSD ] &&
 _man()
 {
-	local cur prev sect manpath UNAME
+	local cur prev sect manpath manext UNAME
+
+	manext="@([0-9lnp]|[0-9][px]|man)?(.@(gz|bz2|lzma))"
 
 	COMPREPLY=()
 	cur=`_get_cword`
@@ -856,15 +858,15 @@
 	
 	case $prev in
 		-l)
-			_filedir;
+			_filedir $manext
 			return 0;
 	esac
 
 	_expand || return 0
 
-	# default completion if parameter contains /
+	# file based completion if parameter contains /
 	if [[ "$cur" == */* ]]; then
-		_filedir
+		_filedir $manext
 		return 0
 	fi
 
@@ -898,10 +900,18 @@
 	# weed out directory path names and paths to man pages
 	COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
 	# strip suffix from man pages
-	COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
+	COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2|lzma)} )
 	COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
 
-	[[ "$prev" != [0-9ln] ]] && _filedir '[0-9ln]'
+	if [[ "$prev" != @([0-9lnp]|[0-9][px]) ]]; then
+		# File based completion for the rest, prepending ./ if needed
+		# (man 1.6f needs that for man pages in current dir)
+		local start=${#COMPREPLY[@]}
+		_filedir $manext
+		for (( i=$start; i < ${#COMPREPLY[@]}; i++ )); do
+			[[ ${COMPREPLY[i]} == */* ]] || COMPREPLY[i]=./${COMPREPLY[i]}
+		done
+	fi
 
 	return 0
 }

=== modified file 'debian/changelog'
--- a/debian/changelog	2009-01-11 22:10:22 +0000
+++ b/debian/changelog	2009-01-11 22:23:32 +0000
@@ -61,6 +61,7 @@
     (Ville Skyttä).
   * Improved features and performance of yum completion (Ville Skyttä).
   * Added support for p (POSIX) and x (x.org) man sections (Ville Skyttä).
+  * Improved filename based man page completion (Ville Skyttä).
   * Merge from Gentoo:
     - fix 'find' completion so that it properly completes on -?(i)whilename.
       Patch by Ciaran McCreesh.



More information about the Bash-completion-commits mailing list