Git Product home page Git Product logo

complete-alias's Introduction

complete-alias

automagical shell alias completion;

  • works with all common aliases, even self-aliases;

  • one completion function, for all aliases;

  • alias completion as easy as type-and-tab;

install

  1. install dependency bash-completion;

    • linux:

      install bash-completion using system package manager:

      dnf install bash-completion     ##  fedora
      apt install bash-completion     ##  debian
      

      for other linux distros, see faq;

    • macos (experimental):

      install bash-completion homebrew formulae version 2:

      brew install bash-completion@2
      
    • windows (experimental):

      see faq;

  2. source complete_alias in ~/.bash_completion:

    . {complete_alias}
    

    where {complete_alias} is the path of complete_alias;

usage

  1. edit aliases to complete in complete_alias:

    for example, to complete aliases foo, bar and baz:

    complete -F _complete_alias foo
    complete -F _complete_alias bar
    complete -F _complete_alias baz
    
  2. to complete an alias, type it and press <tab>;

example

to complete alias sctl aliased to systemctl:

$ alias sctl='systemctl'
$ cp complete_alias ~/.complete_alias
$ echo ". ~/.complete_alias" >> ~/.bash_completion
$ echo "complete -F _complete_alias sctl" >> ~/.complete_alias
$ sctl <tab>
add-requires
add-wants
cancel
cat
condreload
...

config

to config complete-alias, set these envars before sourcing the main script:

  • COMPAL_AUTO_UNMASK

    this is a bool; default is 0; when set to 1, enables auto unmask; when set to 0, uses manual unmask;

    auto unmask automatically manages non-alias command completions, but incurs a small overhead on source; manual unmask is the traditional way of setting non-alias command completions, which is static and faster but requires user intervention if the preset is not satisfying;

compat

  • support for gnu bash(>=4.4) on linux is aimed;

  • support for older versions of bash is uncertain;

  • support for other shells is possible but unlikely;

  • support for other operating systems is experimental;

faq

  • how to install it on windows?

    support for windows is limited to msys2 and git for windows:

    • msys2:

      msys2 features pacman so you can install like linux:

      pacman -S bash-completion
      cat complete_alias >> ~/.bash_completion
      
    • git for windows:

      tldr: steal bash_completion and source it before complete_alias;

      git for windows provides git bash, which is a minimal environment based on msys2; for what matters here, git bash does not have package manager; so the above install procedure does not apply;

      the idea is, you must somehow get bash-completion and load it before complete-alias in a shell environment; for example, you can download bash-completion package from a msys2 mirror; however, the easiest solution i found to make things work is to simply download the main script bash_completion from its git repo; this does not give you its entirety, but is good enough to work;

      now you have 2 files: bash_completion and complete_alias; you need to source them in this order in ~/.bashrc:

      . ~/.bash_completion.sh
      . ~/.complete_alias.sh
      

      attention: here we renamed the files; we cannot use ~/.bash_completion because this is the very filename sourced by the very script; using this filename will cause an infinite loop;

      now install is complete; add your own aliases in ~/.complete_alias.sh;

  • how to install bash-completion on other linux distros?

    these commands are sourced from wikis and users:

    pacman -S bash-completion               ##  arch
    yum install bash-completion             ##  centos
    emerge --ask app-shells/bash-completion ##  gentoo
    zypper install bash-completion          ##  suse
    apt install bash-completion             ##  ubuntu
    

    these commands are not tested; open a ticket if you find them not working;

  • how to complete all my aliases?

    run this one-liner after all aliases have been defined:

    complete -F _complete_alias "${!BASH_ALIASES[@]}"
    

    it works like this:

    complete -F _complete_alias foo
    complete -F _complete_alias bar
    complete -F _complete_alias baz
    ...
    

    note that if you simply put this one-liner in complete_alias code, things may not work, depending on the order of file sourcing, which in turn varies across user configurations; the correct way to use this one-liner is to put it in the same file where aliases are defined; for example, if your aliases are defined in ~/.bashrc, then that file should look like this:

    alias foo='...'
    alias bar='...'
    alias baz='...'
    ...
    complete -F _complete_alias "${!BASH_ALIASES[@]}"
    
  • what are special characters in alias body?

    these characters have special meanings and may cause errors when used in alias body (this is not a complete list):

    • newline (\n):

      we do not allow alias body to contain the newline character; this limits the cases to consider and makes smaller, faster code; we treat a newline as a word breaker in the outmost scope, but you better not rely on this;

    • backquote (`):

      avoid the old-style backquote form `command` of command substitution as much as possible; instead, use the $(command) form; the backquote form is more tricky and less legible when nested in quotes or another command substitution; we do not intend to fully support backquotes;

    • backslash (\):

      avoid backslashes unless you absolutely have to use them; they are mostly used to escape a character; we have double quotes that can do the same; the bash manual is not complete on where a backslash is special and where it is literal; and we may make mistakes on its interpretation;

    • colon (:):

      a colon seems innocent but is special to word completion code: it is one of the characters that breaks words for the completer; you can read more about it at this link; however, we do not guarantee the same treatment of colons here as there; we treat a colon as a word breaker in the outmost scope and a literal otherwise; if you always want it to be a literal, just quote it;

  • why is sudo completion not working correctly?

    there is a known case with sudo that can go wrong; for example:

    $ unalias sudo
    $ complete -r sudo
    $ alias ls='ping'
    $ complete -F _complete_alias ls
    $ sudo ls <tab>
    {ip}
    {ip}
    {ip}
    ...
    

    here we are expecting a list of files, but the completion reply is a list of ip addrs; the reason is, the completion function for sudo is almost always _sudo, which is provided by bash-completion; this function strips sudo then meta-completes the remaining command line; in our case, this is ls to be completed by _complete_alias; but there is no way for _complete_alias to see the original command line, and so it cannot tell ls from sudo ls; as a result, ls and sudo ls are always completed the same even when they should not; unfortunately, there is nothing _complete_alias can do here;

    the easiest solution is to make sudo a self-alias:

    $ alias sudo='sudo'
    $ complete -F _complete_alias sudo
    $ alias ls='ping'
    $ complete -F _complete_alias ls
    $ sudo ls <tab>
    {file}
    {file}
    {file}
    ...
    

    this gives _complete_alias a chance to see the original command line, then decide what is the right thing to do; you may add a trailing space to sudo alias body if you like it that way, and things still work correctly (listing ip addrs is correct in this case):

    $ alias sudo='sudo '
    $ complete -F _complete_alias sudo
    $ alias ls='ping'
    $ complete -F _complete_alias ls
    $ sudo ls <tab>
    {ip}
    {ip}
    {ip}
    ...
    

license

The source code is licensed under the GNU General Public License v3.0.

Copyright (C) 2016-2021 Cyker Way

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

complete-alias's People

Contributors

cykerway avatar hyperupcall avatar krlmlr avatar matthewadams avatar sdondley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

complete-alias's Issues

multi commands alias

Hello,
Thank you for your useful script. I have an issue as the below:

alias apti="apt install"
alias pkgi="apt update && apt install"

λ [~] $ apti
Display all 1507 possibilities? (y or n)
λ [~] $ pkgi

apti <tab>: showing the possible packages for installation

pkgi <tab>: nothing shows

Is it possible to support this case?

aliases with environment variables

First of all, thank you so much for your work. This is a very helpful tool you've created.

I have a bunch of aliases where I prepend it with a variable. Like the below:

alias researchut_dch='DEBEMAIL="[email protected]" DEBFULLNAME="Ritesh Raj Sarraf" dch --force-distribution -Dresearchut '

The bash auto-completion for such aliases does not work. Is it something that is a bug or a limitation ?

`_complete_alias` with environment variable influencing behavior

There are commands that have different completion depending on an environment variable.

E.g. kubeconfig (and oc) will return the pods (in the configured namespace) of the cluster defined in KUBECONFIG.

so

export KUBECONFIG=/path/to/a/kube/config
kubeconfig get po [TAB]

will return the pods in the cluster (and namespace) configured in KUBECONFIG.

Now an alias like alias k-test="KUBECONFIG=/path/to/kube/config kubecfg" with _complete_alias will complete using kubecfg without the KUBECONFIG environment.

Is it possible to somehow set the environment for this specific completion?

"-bash: _completion_loader: command not found" error

On macOS, I was getting this error. I had bash-completion version 1.3.3 installed with homebrew. Uninstalling the old version and reinstalling v2 with brew install bash-completion@2 fixed the issue.

I'll supply a doc patch to mention this fix.

Partial failure with $() in alias

if I define the following aliases :

alias ldocker='docker run -it -v /etc/group:/etc/group:ro -v /etc/passwd:/etc/passwd:ro -u $(id -u $USER):$(id -g $USER)'
alias marcel='docker run -it -v /etc/group:/etc/group:ro -v /etc/passwd:/etc/passwd:ro -u 1000:1000'

the marcel alias autocomplete works flawlessly 👍 for both flags and for arguments (specifically in this case I can autocomplete docker image names)

However in the case of the ldocker alias only flag autocomplete seems to work (both the flag names and the possible arguments for the flags)
normal arguments (as image names) do not autocomplete

changing the $() to a ` syntax doesn't solve the problem, so it probably has to do evaluating in the alias definition?
Is this forbidden somehow?

Does not work with aliases with '--param='

Hello.
Thank you for the script.

But i encountered 1 problem. Autocomplete does not work if alias has certain parameters, e.g

# works
alias ggrep='grep -riP'

# does not work
alias ggrep='grep --exclude-dir=.git'

Create a github release

It looks like this repo has no github release.

I suggest to follow the steps on
https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository#creating-a-release

The created release should show up at
https://github.com/cykerway/complete-alias/releases

The latest release will be accessible at
https://github.com/cykerway/complete-alias/releases/latest

For comparison here are two github repos that do have releases:
https://github.com/mozilla/geckodriver
https://github.com/ryanoasis/nerd-fonts

Doesn't handle ':' in alias name

I have

alias p:='declare -p'
complete -F _complete_alias p:

yet TAB won't complete variable names. p., p? work. complete -v p: also works. Not sure if due to complete_alias or bash-completion.

Does this still work?

The instructions are confusing or I'm too dumb to figure them out or this doesn't work on Debian bullseye anymore running bash 5.1.4. I installed this with apt get bash-completion

I have an alias for docker called "dk".

I created file in home directory called complate_alias with following:

complete -F _complete_alias dk

In a newly created file called .bash_completion in my home dir, I have . /home/admin/complete_alias. I also put the same in ~/.bashrc.

I logged out and back into the shell. Resource all the files above. Still get:

dk <tab>-bash: completion: function _complete_alias' not found`

_completion_loader: command not found

Hi,

On Ubuntu 21.04 with apt install bash-completion,

When invoking my alias I'm getting

_completion_loader: command not found
_command_offset: command not found

afaik, these utils should be provided as part of bash-completion. What am I doing wrong? Thanks.

possible conflicts with fzf

Hi,

This is a follow-up to #40. I'm opening a new issue because the older one has been closed and i've been able to come up with a reproducer.

How to reproduce

Build the following docker file docker build -t compal:gh46 .

Dockerfile
# syntax=docker/dockerfile:1.4
FROM debian:bookworm-slim

RUN <<EOS
  set -ex
  apt update && apt install -y --no-install-recommends \
    bash-completion \
    ca-certificates \
    curl \
    git
  adduser test
EOS

USER test
WORKDIR /home/test

RUN bash <<'EOS'
  set -ex
  git clone --depth=1 https://github.com/cykerway/complete-alias.git compal
  git clone --depth=1 https://github.com/junegunn/fzf.git .fzf
  ./.fzf/install
EOS

COPY <<'EOF' ./.bash_aliases
alias ls="ls --color=auto"
EOF

COPY <<'EOF' ./.bash_completion
source ~/compal/complete_alias
complete -F _complete_alias "${!BASH_ALIASES[@]}"
EOF

Run a bash session in a container:

docker run -it --rm compal:gh46 bash

On the bash prompt, type ls -<TAB>.

The shell enters an infinite loop, reapetedly outputing error: cannot unmask alias command: ls.
Type <Ctrl-C> until you can go back to the prompt and exit.

How to fix

Running docker run -it --rm compal:gh46 tail .bashrc outputs:

if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

[ -f ~/.fzf.bash ] && source ~/.fzf.bash

We can see that the fzf installation script has blindly appended it's source command. The result is that the fzf completion script is sourced after ~./bash_completion (since the latter is itself sourced at the end of /usr/share/bash-completion/bash_completion).

If we instead use the following dockerfile:

Dockerfile
# syntax=docker/dockerfile:1.4
FROM debian:bookworm-slim

RUN <<EOS
  set -ex
  apt update && apt install -y --no-install-recommends \
    bash-completion \
    ca-certificates \
    curl \
    git
  adduser test
EOS

USER test
WORKDIR /home/test

RUN bash <<'EOS'
  set -ex
  git clone --depth=1 https://github.com/cykerway/complete-alias.git compal
  git clone --depth=1 https://github.com/junegunn/fzf.git .fzf
  ./.fzf/install --no-update-rc
EOS

COPY <<'EOF' ./.bash_aliases
alias ls="ls --color=auto"
EOF

COPY <<'EOF' ./.bash_completion
source ~/.fzf.bash
source ~/compal/complete_alias
complete -F _complete_alias "${!BASH_ALIASES[@]}"
EOF

Then typing ls -<TAB><TAB><TAB> correctly shows the ls option completions, but typing ls /etc/**<TAB> does not show the fzf path completions.

If we now export COMPAL_AUTO_UNMASK=1 at the top of ~/.bash_completion, then typing ls -<TAB><TAB><TAB> correctly shows the ls option completions, and typing ls /etc/**<TAB> correctly shows the fzf path completions.

Final notes

I do not have the knowledge required to find tha actual cause of the issue, nor to tell if it's a bug in complete-alias, fzf, bash itself or just a fundamental limitation of the bash completion system...

However I think that this might warrant an entry in the docs stating that care should be taken that, in presence of other completion handlers, complete_alias should be sourced last, and that the COMPAL_AUTO_UNMASK setting may resolve some conflicts.

Pattern will never match

Line 777: This pattern never matches because of a previous pattern on line 761.

command is already checked for in line 761, so line 777 will never be called.

__compal__unmask_alias_manual() {
  local cmd="$1"
  
  case "$cmd" in
    ...
    ...
    ...    👇
    761: command | type | which )
             complete -c "$cmd"
             ;;
    ...
    ...           👇
    777: aoss | command | do | else ... )
             complete -F _command "$cmd"
             ;;
    ...)
  esac
}

https://github.com/cykerway/complete-alias/blob/7f2555c2fe7a1f248ed2d4301e46c8eebcbbc4e2/complete_alias#L777C14-L777C21

Make available as package

I generally dislike checking GitHub for updates of software I use. This is just a single file, but never the less, it's exceptionally useful and I'd like my package manager to handle keeping it up to date with any future changes. :)

To that end, I used the OpenSUSE Open Build Service to set up a project hosting the build of packages, and assembled a spec file for generating RPMs on SUSE and RedHat/Fedora. If there's interest, I'll also do the Debian/Ubuntu packaging at the same place (I make more RPMs recently, so that's where I started). I have it set up for my fork to automatically trigger builds upon creation of a new tag, but I'd be more than happy to shift maintainership over to this project so I can kill the automation which syncs my fork. It's just a matter of adding a webhook to the GitHub project with a token (I'll share mine if no one here wants to create an openbuild account) and continuing to use tags for new releases; I've done the rest of the work to automatically build packages and generate the changelog (PR coming). If that's not something of interest, that's ok - I'll just keep mirroring the project to my own fork. :)

The resulting packages (and OS-appropriate repositories) are available at https://software.opensuse.org/package/bash-complete-alias.

Not working with `alias gitdiff="GIT_DIR= git diff"`

I'm trying to get complete-alias to work with the following alias (which lets me use the extended features of Git's git diff command on non-versioned files, outside of any repository):

alias gitdiff="GIT_DIR= git diff"

As completion setup, I use:

complete -F _complete_alias gitdiff

When I try the alias as follows, I don't get any completions:

$ gitdiff --<TAB>

I have setup Git completions, and the following gets me completions of its long options as expected:

$ GIT_DIR= git diff --<TAB>

It doesn't work

I did all you said in a ubuntu 16.0 but when I type an alias and hit tab simply nothing happens, except for showing all available command which I had before this too.

Borked on macOS

This is borked due to differences in sed on macOS. GNU sed uses sed -r, but macOS (BSD) uses sed -e.

matthew@newt:~
$ kubectl get
certificatesigningrequest  endpoints                  persistentvolume           rolebinding
clusterrolebinding         event                      persistentvolumeclaim      secret
componentstatus            horizontalpodautoscaler    pod                        service
configmap                  ingress                    poddisruptionbudget        serviceaccount
controllerrevision         job                        podsecuritypolicy          statefulset
cronjob                    namespace                  podtemplate                status
daemonset                  networkpolicy              replicaset                 storageclass
deployment                 node                       replicationcontroller
matthew@newt:~
$ kubectl get ^C
matthew@newt:~
$ k get sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
^C
matthew@newt:~

completion issues when alias contains a colon

I have an alias that runs a docker container and mounts my work directory inside the container:

alias dkrun='docker run -it --rm --volume $HOME/workdir:$HOME/workdir --workdir $HOME/workdir'

When I type dkrun<TAB><TAB> it should show a list of available images on my system, but complete-alias doesn't seem to like the --volume option because of the colon. If I remove the --volume option from the alias (or even just the colon), then the completion works as expected, and it displays the list of images.

hardware: MacBook Pro (16-inch, 2021) with Apple M1 Pro
OS: macOS Monterey version 12.4
GNU bash: version 5.1.16(1)-release (aarch64-apple-darwin21.1.0)
bash-completion v2 installed using homebrew

I thought that maybe the Apple M1 Pro might be causing the issue, so I also tested the scenario inside a linux/amd64 container:

docker run -it --rm --platform linux/amd64 --volume /var/run/docker.sock:/var/run/docker.sock ubuntu:focal

Inside the container, I installed bash-completion, docker.io, and complete-alias. Then I created the dkrun alias as before and sourced .bash_completion, but the completion still doesn't work when the alias contains a colon.

Incidentally, while the completion does not display the list of available images as expected, if I type dkrun --<TAB><TAB> then it does complete the list of long options available to the docker run command.

I used to have a MacBook Pro (16-inch, 2019) with Intel Core i7 and macOS Monterey, and completion worked fine.

How to get this working in git-bash on windows ?

Thanks for this useful tool. I am on windows, and it works described on wsl-1 and wsl-2 on windows, but cannot get it to work for git-bash on windows, using the same instructions.

Any suggestions ?

doc: Clarify the way to enable `auto-unmask`

Hi there,

to enable aliases auto-unmasking, the Readme just says:

set COMPAL_AUTO_UNMASK to 1

but the last line of the script also says:

to complete all aliases, run this line after all aliases have been defined;
#complete -F _complete_alias "${!BASH_ALIASES[@]}"

Which way is the right one?

(Thanks for this awesome tool BTW, it works perfectly fine with Debian 11 and ~ 140 aliases)

Shell stops echoing typed characters after tab-completing (and exiting) blocking operations on remote machines

First of all, thank you for sharing this, I have used it for a while and it has been really helpful!

I noticed this issue recently; I wasn't able to figure out what was causing it by looking at the code, and I was wondering if you knew of a fix. Here is how to reproduce:

First, ssh into a remote machine (mine is on AWS).

Then create an alias for a command that blocks. My use case is kubectl logs -f, but tail -f will exhibit the same issue.

Then tab-complete the alias, press enter to run the command, and then CTRL+C to kill the streaming tail command.

Afterwards, the terminal does not show what I type, although it does go through (e.g. if I type ls and enter, it will list my directory). Running reset restores the shell properly.

Have you seen this behavior, and do you know of a potential fix? I found these posts which may or may not be helpful:

Thank you!

bad math expression in zsh

when i run source ~/.zshrc
I get the following error when integrate complete-alias to zsh

__compal__main:1: bad math expression: illegal character: "

this my .zshrc script

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

ZSH_THEME="robbyrussell"

plugins=(git)

source $ZSH/oh-my-zsh.sh

# Path
export PATH="$PATH:/home/laptop/.config/composer/vendor/bin"

# Completion Alias
source ~/.bash_completion.d/complete_alias

# Aliases
alias zshconfig="mousepad ~/.zshrc"
alias ohmyzsh="mousepad ~/.oh-my-zsh"
alias c="clear"
alias l="ls -all"

# Systemctl Aliases
alias sstart="sudo systemclt start"
alias sstop="sudo systemclt stop"
alias srestart="sudo systemclt restart"
alias senable="sudo systemclt enable"
alias sdisable="sudo systemclt disable"

complete -F _complete_alias "${!BASH_ALIASES[@]}"

You may need this information
OS : Manjaro with XFCE

Difficulty with `complete -C` commands

I use certain utility packages to manage multiple versions of a given utility. One such is tfenv to manage Terraform. This sets up my PATH such that the executable file named terraform is symlinked to a script that invokes the appropriate actual instance. Command completion works without issue. I would like to set up an alias, e.g.:
alias tfinit='terraform init ... $@'
but I find that this gives me errors like:
-bash: compgen: warning: -C option may not work as you expect

Is this possible? What can I do to help complete-alias DWIM?

Thanks,
Matt

alias 'eats' space on VS Code aliases

Info:

$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-redhat-linux-gnu)
# VS Code is installed and 'code' is a command to run it

Problem:

$ mkdir foo
$ cd foo
$ touch bar
$ code [tab] # transforms to "code bar "
$ alias code='code --goto'
$ complete -F _complete_alias code
$ source ~/.bash_completion.d/complete_alias
$ code [tab] # transforms to "code bar", no space at the end

I did not met any problems with any other aliased comands
(including vi, subl, etc that also have file[:line[:column]] or file[ +line] syntax).
So I think it is more VS Code's problem rather than this script's one.
Still if it may be somehow solved, it would be beautiful.

'_complete_alias' not found

When pressing tab to complete an alias, bash throws an error:

bash: completion: function `_complete_alias' not found

[shellcheck] errors

In /usr/share/bash-complete-alias/complete_alias line 296:
            elif [[ '(' == "${str:j:1}" ]]; then
            ^-- SC1009 (info): The mentioned syntax error was in this elif clause.
                 ^-- SC1073 (error): Couldn't parse this test expression. Fix to allow more checks.
                    ^-- SC1029 (error): In [[..]] you shouldn't escape ( or ).
                        ^-- SC1108 (error): You need a space before and after the == .
                            ^-- SC1072 (error): Expected comparison operator (don't wrap commands in []/[[]]). Fix any mentioned problems and try again.

For more information:
  https://www.shellcheck.net/wiki/SC1029 -- In [[..]] you shouldn't escape ( ...
  https://www.shellcheck.net/wiki/SC1108 -- You need a space before and after...
  https://www.shellcheck.net/wiki/SC1072 -- Expected comparison operator (don...

Autoenabling completion for all aliases

Just an idea that you may want to add to the README or something. (Or not.)

Since I have a couple dozen aliases, I recently replaced all the

complete -F _complete_alias foo
complete -F _complete_alias bar
complete -F _complete_alias baz
...

with this in my .bashrc:

for a in ${!BASH_ALIASES[*]}; do
    complete -F _complete_alias $a
done

So far everything has been working like a charm.

And big thanks for this awesome script! It's a life saver.

getting bash: _command_offset: command not found - on windows, git bash

hi guys,

i can't seem to get this working on windows, have tried to follow instructions in the readme and especially the FAQ section about windows but finding it pretty confusing.

I've got both files bash_completion.sh and complete_alias.sh in the .bash_completion.d directory, and i'm sourcing them in the specified order in my bash_profile file for git bash:
source ~/.bash_completion.d/bash_completion.sh
source ~/.bash_completion.d/complete_alias.sh

I've also added this to the end of my bash profile, as well as trying to specify the aliases by name:
complete -F _complete_alias "${!BASH_ALIASES[@]}"

Not super clear on what i should be editing or adding to the two repo .sh files above, i tried a few things from the readme adding to both files but nothing seemed to work.

Any help much appreciated

consider whether this could be merged into bash-completion

Hey there.

Thanks for your nice tool.
It's really something that should be available out-of-the box on every system.

For that reason, would you consider to merge it into bash-completion?
That would have the advantage, that it gets more widespread on readily available (sooner or later) in basically every distribution.

The bash-completion maintainer seemed to be open for such an idea, if you'd continue with the maintenance of the tool there.

Cheers,
Chris.

Git tag rewrite

Hi @cykerway,

I packaged and maintained the complete-alias AUR package for easy installation and update on Arch LInux.
As
I would highly appreciate that git tags would not be rewritten and break checksumming of the fetched tarball. Please tag a new release instead. It can be a patch release (MAJOR.MINOR.PATCH).

thanks

this package is fantastic, and very easy to set up! thanks for writing it! 🎉

"error: cannot unmask alias command:"

Hi,

I face a bug when using complete-alias with aliases such as alias mv='mv -i'

How to reproduce this bug

Install

  • install bash-completion: sudo apt install bash-completion
  • download complete_alias from Github
  • paste in ~/.bashrc.d/completion-aliases.bashrc
  • source from .bashrc
  • enable auto unmask with modifications of the lines COMPAL_AUTO_UNMASK=1 and complete -F _complete_alias "${!BASH_ALIASES[@]}"

At this point everything works fine, auto unmasking works great.

The bug

The bug appears when writing mv then hitting Tab:

error: cannot unmask alias command: mv
error: cannot unmask alias command: mv
error: cannot unmask alias command: mv
error: cannot unmask alias command: mv
error: cannot unmask alias command: mv
error: cannot unmask alias command: mv

Note that the same issue happens with alias rm='rm -i' and alias cp='cp -i'

Any hint?

Config

  • Debian 11
  • GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu)

README documentation minor suggestions

Wonderful project. Some comments on documentation:

  • it's not clear from the README whether this works for multi-word aliases (such as alias apti='apt install'). In fact, it does, which is very nice, and should perhaps be mentioned in the description / examples
  • the README suggests "appending" complete_alias to ~/.bash_completion (presumably, after everything that's already in there). And then adding some more completions (separated from the initial ones by the complete_alias code blob). Perhaps it makes more sense to insert complete_alias at the top of the file, or, better yet, source it from the cloned git repo, as the user may want to get updates

Also, there is a way to install complete_alias for all visible aliases which might also be interesting for users:

complete -F _complete_alias $(alias | perl -lwne 'print $1 if /^alias ([^=]+)=/')

Slow sourcing time

Before adding this my bashrc took roughly 200ms to load. With this enabled for 6 aliases it takes roughly 600ms which is a bit much for my liking. Do you think this could be improved?

issue on complete

Hi

After install, i got this message when i attempt to auto_complete a command when i press "tab".
-bash: compgen: warning: -C option may not work as you expect

I'm using ubuntu
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.