[Sarlug] Bash completion
    max at gamer.yandex.ru 
    max at gamer.yandex.ru
       
    Fri Jan 31 17:23:11 MSK 2003
    
    
  
Народ. Может кому пригодится : скрипт, который в bash'е по TAB дописывает 
имена man топиков. Мне лично его очень недостовало.
------------------------Cut here--------------------
#!/bin/bash
#
#  Function:
#    complete_man() - assigns COMPREPLY variable list of man topics,
#                     which are expanded from given argument
#  Arguments:
#     $1 - not used (reserved for use with bash's "Programmable completion")
#     $2 - first part of topic name
#     $3 - colon-separated section list (or 'man' for default)
function complete_man() {
    #local section=, result=, script=
    section=
    # Check for section parameter
    if [[ "$3" != "man" ]]; then
	section="-S $3"
    fi
    # Get topic list and filter pathnames
    result=`man ${section} -aW ${2}* 2>/dev/null | sed -ne "s|.*/||p"`
    # Get archive extensions recognized by man
    archive_extensions=(`cat /etc/man.conf | gawk -F " " '{ if($1 ~ /\./) 
print $1; }'`)
    # Strip archive extension
    for arch_ext in $archive_extensions; do
	script="s/\\${arch_ext}//gp"
	result=`echo $result | sed -ne $script`
    done;
    # Strip section number
    result=`echo $result | sed -ne "s/\.[0-9]//gp"`
    COMPREPLY=($result)
}
------------------------Cut here--------------------
Прикручивается это так: в ~/.bashrc пишем строчки
source <путь до файла>/complete_man.sh
complete -F "complete_man" man
Если будут какие-нибудь проблемы - пишите...
    
    
More information about the Sarlug
mailing list