Autocompletamento Terminale

Installazione, configurazione e uso di programmi e strumenti.
Scrivi risposta
morris2003
Prode Principiante
Messaggi: 73
Iscrizione: sabato 24 aprile 2010, 12:08

Autocompletamento Terminale

Messaggio da morris2003 »

Ho Ubuntu 11.04 e nelle versioni più vecchie di ubuntu, il terminale aveva una funzione di autocompletamento non solo per file e cartelle ma anche per le applicazioni installate. Il problema che vi pongo è semplice: come posso riattivare quella funzione?

Ho seguito le istruzioni elencate http://forum.ubuntu-it.org/viewtopic.php?t=428677 ma non funzionano.
Avatar utente
vaillant
Rampante Reduce
Rampante Reduce
Messaggi: 8319
Iscrizione: domenica 15 marzo 2009, 9:54
Distribuzione: Ubuntu Server 20.04 LTS
Sesso: Maschile
Località: Modica

Re: Autocompletamento Terminale

Messaggio da vaillant »

Posta il risultato di

Codice: Seleziona tutto

cat /etc/bash.bashrc
morris2003
Prode Principiante
Messaggi: 73
Iscrizione: sabato 24 aprile 2010, 12:08

Re: Autocompletamento Terminale

Messaggio da morris2003 »

Codice: Seleziona tutto

morris2003@helloworld:~$ cat /etc/bash.bashrc
# System-wide .bashrc file for interactive bash(1) shells.

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, overwrite the one in /etc/profile)
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
#    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
#    ;;
#*)
#    ;;
#esac

# enable bash completion in interactive shells
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

# sudo hint
if [ ! -e "$HOME/.sudo_as_admin_successful" ]; then
    case " $(groups) " in *\ admin\ *)
    if [ -x /usr/bin/sudo ]; then
        cat <<-EOF
        To run a command as administrator (user "root"), use "sudo <command>".
        See "man sudo_root" for details.

        EOF
    fi
    esac
fi

# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found ]; then
        function command_not_found_handle {
                # check because c-n-f could've been removed in the meantime
                if [ -x /usr/lib/command-not-found ]; then
                   /usr/bin/python /usr/lib/command-not-found -- $1
                   return $?
                elif [ -x /usr/share/command-not-found ]; then
                   /usr/bin/python /usr/share/command-not-found -- $1
                   return $?
                else
                   return 127
                fi
        }
fi
Avatar utente
vaillant
Rampante Reduce
Rampante Reduce
Messaggi: 8319
Iscrizione: domenica 15 marzo 2009, 9:54
Distribuzione: Ubuntu Server 20.04 LTS
Sesso: Maschile
Località: Modica

Re: Autocompletamento Terminale

Messaggio da vaillant »

Verifica di avere il pacchetto installato

Codice: Seleziona tutto

dpkg -l bash-completion
morris2003
Prode Principiante
Messaggi: 73
Iscrizione: sabato 24 aprile 2010, 12:08

Re: Autocompletamento Terminale

Messaggio da morris2003 »

Da Synaptic risulta installato, ho provato pure a reinstallarlo...

cmq dpkg mi restituisce:

Codice: Seleziona tutto

morris2003@helloworld:~$ dpkg -l bash-completion
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Nome           Versione       Descrizione
+++-==============-==============-============================================
ii  bash-completio 1:1.3-1ubuntu3 programmable completion for the bash shell
Avatar utente
vaillant
Rampante Reduce
Rampante Reduce
Messaggi: 8319
Iscrizione: domenica 15 marzo 2009, 9:54
Distribuzione: Ubuntu Server 20.04 LTS
Sesso: Maschile
Località: Modica

Re: Autocompletamento Terminale

Messaggio da vaillant »

Dai

Codice: Seleziona tutto

sudo gedit /etc/bash.bashrc
cerca queste righe

Codice: Seleziona tutto

# enable bash completion in interactive shells
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi
e falle diventare così

Codice: Seleziona tutto

# enable bash completion in interactive shells
# if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi
salva il file, chiudilo. Poi chiudi il terminale, riaprilo e fai una prova
morris2003
Prode Principiante
Messaggi: 73
Iscrizione: sabato 24 aprile 2010, 12:08

Re: Autocompletamento Terminale

Messaggio da morris2003 »

Non cambia nulla :(
Avatar utente
vaillant
Rampante Reduce
Rampante Reduce
Messaggi: 8319
Iscrizione: domenica 15 marzo 2009, 9:54
Distribuzione: Ubuntu Server 20.04 LTS
Sesso: Maschile
Località: Modica

Re: Autocompletamento Terminale

Messaggio da vaillant »

Rimetti quelle righe com'erano prima e postami

Codice: Seleziona tutto

ls /etc/bash_completion.d/
morris2003
Prode Principiante
Messaggi: 73
Iscrizione: sabato 24 aprile 2010, 12:08

Re: Autocompletamento Terminale

Messaggio da morris2003 »

Ecco

Codice: Seleziona tutto

morris2003@helloworld:~$ ls /etc/bash_completion.d/
abook                  freerdp          man                rrdtool
ant                    fuse             mc                 rsync
apache2ctl             gcc              mcrypt             rtcwake
apport_completion      gcl              mdadm              samba
apt                    gdb              medusa             sbcl
apt-build              genisoimage      minicom            screen
aptitude               getent           mkinitrd           service
aspell                 gkrellm          module-init-tools  sh
autoconf               gnatmake         monodevelop        shadow
automake               gpg              mount              sitecopy
autorpm                gpg2             mplayer            smartctl
axi-cache              grub             msynctool          snownews
bash-builtins          gzip             munin-node         sqlite3
bind-utils             heimdal          mutt               ssh
bitkeeper              helpers          mysqladmin         sshfs
bittorrent             hping2           ncftp              strace
bluez                  iconv            net-tools          svk
brctl                  iftop            nmap               sysbench
bzip2                  ifupdown         ntpdate            sysctl
cardctl                imagemagick      open-iscsi         sysv-rc
cfengine               info             openldap           tar
chkconfig              initramfs-tools  openssl            tcpdump
chsh                   insserv          p4                 ufw
cksfv                  ipmitool         perl               unace
clisp                  iproute2         pine               unrar
configure              ipsec            pkg-config         update-alternatives
coreutils              iptables         pkg_install        upstart
cowsay                 ipv6calc         pkgtools           util-linux
cpan2dist              isql             pm-utils           vncviewer
cpio                   jar              portupgrade        vpnc
crontab                java             postfix            wireless-tools
cryptsetup             k3b              postgresql         wodim
cups                   kldload          povray             wol
cvs                    larch            procps             wtf
cvsps                  ldapvi           python             wvdial
dd                     lftp             qdbus              xhost
debconf                lilo             qemu               xm
desktop-file-validate  links            quota-tools        xmllint
dhclient               lintian          rcs                xmlwf
dict                   lisp             rdesktop           xmms
dpkg                   lrzip            reportbug          xmodmap
dselect                lsof             resolvconf         xrandr
dsniff                 lvm              rfkill             xrdb
dvd+rw-tools           lzma             ri                 xsltproc
e2fsprogs              lzop             rpcdebug           xz
findutils              mailman          rpm                yp-tools
freeciv                make             rpmcheck           yum-arch
Avatar utente
vaillant
Rampante Reduce
Rampante Reduce
Messaggi: 8319
Iscrizione: domenica 15 marzo 2009, 9:54
Distribuzione: Ubuntu Server 20.04 LTS
Sesso: Maschile
Località: Modica

Re: Autocompletamento Terminale

Messaggio da vaillant »

Per caso hai installato il pacchetto acroread?

Codice: Seleziona tutto

dpkg -l acroread
morris2003
Prode Principiante
Messaggi: 73
Iscrizione: sabato 24 aprile 2010, 12:08

Re: Autocompletamento Terminale

Messaggio da morris2003 »

Non è installato
Avatar utente
vaillant
Rampante Reduce
Rampante Reduce
Messaggi: 8319
Iscrizione: domenica 15 marzo 2009, 9:54
Distribuzione: Ubuntu Server 20.04 LTS
Sesso: Maschile
Località: Modica

Re: Autocompletamento Terminale

Messaggio da vaillant »

Postami

Codice: Seleziona tutto

cat -n /etc/bash_completion
morris2003
Prode Principiante
Messaggi: 73
Iscrizione: sabato 24 aprile 2010, 12:08

Re: Autocompletamento Terminale

Messaggio da morris2003 »

Codice: Seleziona tutto

  1491      if [[ $COMP_CWORD -eq 0 ]]; then
  1492          _compopt_o_filenames
  1493          COMPREPLY=( $( compgen -c -- "$cur" ) )
  1494      else
  1495          cmd=${COMP_WORDS[0]}
  1496          if complete -p ${cmd##*/} &>/dev/null; then
  1497              cspec=$( complete -p ${cmd##*/} )
  1498              if [ "${cspec#* -F }" != "$cspec" ]; then
  1499                  # complete -F <function>
  1500
  1501                  # get function name
  1502                  func=${cspec#*-F }
  1503                  func=${func%% *}
  1504
  1505                  if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
  1506                      $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" "${COMP_WORDS[${#COMP_WORDS[@]}-2]}"
  1507                  else
  1508                      $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}"
  1509                  fi
  1510
  1511                  # remove any \: generated by a command that doesn't
  1512                  # default to filenames or dirnames (e.g. sudo chown)
  1513                  # FIXME: I'm pretty sure this does not work!
  1514                  if [ "${cspec#*-o }" != "$cspec" ]; then
  1515                      cspec=${cspec#*-o }
  1516                      cspec=${cspec%% *}
  1517                      if [[ "$cspec" != @(dir|file)names ]]; then
  1518                          COMPREPLY=("${COMPREPLY[@]//\\\\:/:}")
  1519                      else
  1520                          _compopt_o_filenames
  1521                      fi
  1522                  fi
  1523              elif [ -n "$cspec" ]; then
  1524                  cspec=${cspec#complete};
  1525                  cspec=${cspec%%${cmd##*/}};
  1526                  COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) );
  1527              fi
  1528          elif [ ${#COMPREPLY[@]} -eq 0 ]; then
  1529              _filedir
  1530          fi
  1531      fi
  1532  }
  1533  complete -F _command aoss command do else eval exec ltrace nice nohup padsp \
  1534      then time tsocks vsound xargs
  1535
  1536  _root_command()
  1537  {
  1538      local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
  1539      local root_command=$1
  1540      _command $1 $2 $3
  1541  }
  1542  complete -F _root_command fakeroot gksu gksudo kdesudo really sudo
  1543
  1544  # Return true if the completion should be treated as running as root
  1545  _complete_as_root()
  1546  {
  1547      [[ $EUID -eq 0 || ${root_command:-} ]]
  1548  }
  1549
  1550  _longopt()
  1551  {
  1552      local cur prev split=false
  1553      _get_comp_words_by_ref -n = cur prev
  1554
  1555      _split_longopt && split=true
  1556
  1557      case "$prev" in
  1558          --*[Dd][Ii][Rr]*)
  1559              _filedir -d
  1560              return 0
  1561              ;;
  1562          --*[Ff][Ii][Ll][Ee]*|--*[Pp][Aa][Tt][Hh]*)
  1563              _filedir
  1564              return 0
  1565              ;;
  1566      esac
  1567
  1568      $split && return 0
  1569
  1570      if [[ "$cur" == -* ]]; then
  1571          COMPREPLY=( $( compgen -W "$( $1 --help 2>&1 | \
  1572              sed -ne 's/.*\(--[-A-Za-z0-9]\{1,\}\).*/\1/p' | sort -u )" \
  1573              -- "$cur" ) )
  1574      elif [[ "$1" == @(mk|rm)dir ]]; then
  1575          _filedir -d
  1576      else
  1577          _filedir
  1578      fi
  1579  }
  1580  # makeinfo and texi2dvi are defined elsewhere.
  1581  for i in a2ps awk bash bc bison cat colordiff cp csplit \
  1582      curl cut date df diff dir du enscript env expand fmt fold gperf gprof \
  1583      grep grub head indent irb ld ldd less ln ls m4 md5sum mkdir mkfifo mknod \
  1584      mv netstat nl nm objcopy objdump od paste patch pr ptx readelf rm rmdir \
  1585      sed seq sha{,1,224,256,384,512}sum shar sort split strip tac tail tee \
  1586      texindex touch tr uname unexpand uniq units vdir wc wget who; do
  1587      have $i && complete -F _longopt -o default $i
  1588  done
  1589  unset i
  1590
  1591  _filedir_xspec()
  1592  {
  1593      local IFS cur xspec
  1594
  1595      IFS=$'\n'
  1596      COMPREPLY=()
  1597      _get_comp_words_by_ref cur
  1598
  1599      _expand || return 0
  1600
  1601      # get first exclusion compspec that matches this command
  1602      xspec=$( awk "/^complete[ \t]+.*[ \t]${1##*/}([ \t]|\$)/ { print \$0; exit }" \
  1603          "$BASH_COMPLETION" )
  1604      # prune to leave nothing but the -X spec
  1605      xspec=${xspec#*-X }
  1606      xspec=${xspec%% *}
  1607
  1608      local -a toks
  1609      local tmp
  1610
  1611      toks=( ${toks[@]-} $(
  1612          compgen -d -- "$(quote_readline "$cur")" | {
  1613          while read -r tmp; do
  1614              # see long TODO comment in _filedir() --David
  1615              printf '%s\n' $tmp
  1616          done
  1617          }
  1618          ))
  1619
  1620      # Munge xspec to contain uppercase version too
  1621      eval xspec="${xspec}"
  1622      local matchop=!
  1623      if [[ $xspec == !* ]]; then
  1624          xspec=${xspec#!}
  1625          matchop=@
  1626      fi
  1627      [[ ${BASH_VERSINFO[0]} -ge 4 ]] && \
  1628          xspec="$matchop($xspec|${xspec^^})" || \
  1629          xspec="$matchop($xspec|$(printf %s $xspec | tr '[:lower:]' '[:upper:]'))"
  1630
  1631      toks=( ${toks[@]-} $(
  1632          eval compgen -f -X "!$xspec" -- "\$(quote_readline "\$cur")" | {
  1633          while read -r tmp; do
  1634              [ -n $tmp ] && printf '%s\n' $tmp
  1635          done
  1636          }
  1637          ))
  1638
  1639      [ ${#toks[@]} -ne 0 ] && _compopt_o_filenames
  1640      COMPREPLY=( "${toks[@]}" )
  1641  }
  1642  list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' "$BASH_COMPLETION" | \
  1643      # read exclusion compspecs
  1644      (
  1645      while read line
  1646      do
  1647          # ignore compspecs that are commented out
  1648          if [ "${line#\#}" != "$line" ]; then continue; fi
  1649          line=${line%# START exclude*}
  1650          line=${line%# FINISH exclude*}
  1651          line=${line##*\'}
  1652          list=( "${list[@]}" $line )
  1653      done
  1654      printf '%s ' "${list[@]}"
  1655      )
  1656      ) )
  1657  # remove previous compspecs
  1658  if [ ${#list[@]} -gt 0 ]; then
  1659      eval complete -r ${list[@]}
  1660      # install new compspecs
  1661      eval complete -F _filedir_xspec "${list[@]}"
  1662  fi
  1663  unset list
  1664
  1665  # source completion directory definitions
  1666  if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \
  1667      -x $BASH_COMPLETION_COMPAT_DIR ]]; then
  1668      for i in $(LC_ALL=C command ls "$BASH_COMPLETION_COMPAT_DIR"); do
  1669          i=$BASH_COMPLETION_COMPAT_DIR/$i
  1670          [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)|Makefile*) \
  1671              && -f $i && -r $i ]] && . "$i"
  1672      done
  1673  fi
  1674  if [[ $BASH_COMPLETION_DIR != $BASH_COMPLETION_COMPAT_DIR && \
  1675      -d $BASH_COMPLETION_DIR && -r $BASH_COMPLETION_DIR && \
  1676      -x $BASH_COMPLETION_DIR ]]; then
  1677      for i in $(LC_ALL=C command ls "$BASH_COMPLETION_DIR"); do
  1678          i=$BASH_COMPLETION_DIR/$i
  1679          [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)|Makefile*) \
  1680              && -f $i && -r $i ]] && . "$i"
  1681      done
  1682  fi
  1683  unset i
  1684
  1685  # source user completion file
  1686  [[ $BASH_COMPLETION != ~/.bash_completion && -r ~/.bash_completion ]] \
  1687      && . ~/.bash_completion
  1688  unset -f have
  1689  unset UNAME USERLAND have
  1690
  1691  set $BASH_COMPLETION_ORIGINAL_V_VALUE
  1692  unset BASH_COMPLETION_ORIGINAL_V_VALUE
  1693
  1694  # Local variables:
  1695  # mode: shell-script
  1696  # sh-basic-offset: 4
  1697  # sh-indent-comment: t
  1698  # indent-tabs-mode: nil
  1699  # End:
  1700  # ex: ts=4 sw=4 et filetype=sh
Avatar utente
vaillant
Rampante Reduce
Rampante Reduce
Messaggi: 8319
Iscrizione: domenica 15 marzo 2009, 9:54
Distribuzione: Ubuntu Server 20.04 LTS
Sesso: Maschile
Località: Modica

Re: Autocompletamento Terminale

Messaggio da vaillant »

Allora

Codice: Seleziona tutto

sudo cp /etc/bash_completion /etc/bash_completion.old
sudo gedit /etc/bash_completion
cerca la riga n. 1587 e modificala da così

Codice: Seleziona tutto

have $i && complete -F _longopt -o default $i
a così

Codice: Seleziona tutto

have $i && complete -F _longopt -o filenames $i
poi al solito salvi il file e lo chiudi.

Per vedere i numeri di riga in gedit puoi andare in Modifica->Preferenze e mettere la spunta su "Mostrare inumeri di riga"
morris2003
Prode Principiante
Messaggi: 73
Iscrizione: sabato 24 aprile 2010, 12:08

Re: Autocompletamento Terminale

Messaggio da morris2003 »

Non cambia nulla :(
Avatar utente
vaillant
Rampante Reduce
Rampante Reduce
Messaggi: 8319
Iscrizione: domenica 15 marzo 2009, 9:54
Distribuzione: Ubuntu Server 20.04 LTS
Sesso: Maschile
Località: Modica

Re: Autocompletamento Terminale

Messaggio da vaillant »

Mi spiace allora, non so cos'altro consigliarti :-\
morris2003
Prode Principiante
Messaggi: 73
Iscrizione: sabato 24 aprile 2010, 12:08

Re: Autocompletamento Terminale

Messaggio da morris2003 »

Grazie del tuo tempo...sarà un bug allora :(
Avatar utente
vaillant
Rampante Reduce
Rampante Reduce
Messaggi: 8319
Iscrizione: domenica 15 marzo 2009, 9:54
Distribuzione: Ubuntu Server 20.04 LTS
Sesso: Maschile
Località: Modica

Re: Autocompletamento Terminale

Messaggio da vaillant »

C'è questo bug segnalato e la risposta n. 10 ha risolto il problema a diversi utenti ma con te non ha funzionato.

Se sei iscritto su Launchpad puoi iscriverti e segnalare che ne sei affetto
Scrivi risposta

Ritorna a “Applicazioni”

Chi c’è in linea

Visualizzano questa sezione: 0 utenti iscritti e 11 ospiti