Code Monkey home page Code Monkey logo

carapace-bridge's Introduction

carapace-bridge's People

Contributors

dependabot[bot] avatar karanahlawat avatar rsteube avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

r0uv3n

carapace-bridge's Issues

Incorrect `bash-completion` directory path when `XDG_DATA_HOME` is present.

In the bash.go file, when creating the list of locations to look for completions, if the user doesn't have BASH_COMPLETION_USER_DIR set, but does have XDG_DATA_HOME set, then the location it adds to the list ends up being XDG_DATA_HOME/.local/share/bash-completion/completions. However, in most cases, the value of XDG_DATA_HOME itself is set to /home/user/.local/share. So, the location ends up being, /home/user/.local/share/.local/share/bash-completion/completions, which is incorrect as the directory doesn't exist.

The fix is pretty small, and easy to implement. Please let me know if I should raise a PR for it.

bash bridge spams a script to bash history

Any idea why this entire script, line by line, goes into the bash history when I try to complete a command using bash bridge in both nushell and fish?

#!/bin/bash
COMP_WORDS=($COMP_LINE)
if [ "${COMP_LINE: -1}" = " " ]; then
COMP_WORDS+=("")
fi
COMP_CWORD=$((${#COMP_WORDS[@]} - 1))
COMP_POINT=${#COMP_LINE}
# bash-completions
[ -f /data/data/com.termux/files/usr/share/bash-completion/bash_completion ] && source /data/data/com.termux/files/usr/share/bash-completion/bash_completion # termux
[ -f /usr/local/share/bash-completion/bash_completion ] && source /usr/local/share/bash-completion/bash_completion # osx
[ -f /usr/share/bash-completion/bash_completion ] && source /usr/share/bash-completion/bash_completion # linux
__load_completion "${COMP_WORDS[0]}"
$"$(complete -p "${COMP_WORDS[0]}" | sed -r 's/.* -F ([^ ]+).*/\1/')"
for i in "${COMPREPLY[@]}"; do
if [[ -d "${i}" && "${i}" != */ ]]; then
echo "${i}/"
else
echo "${i}"
fi
done

Every time I try to get a complete for the arguments of nix-store, it causes the bash history to be filled with the contents of the script:

# ~/.bash_history
j n c
fish
git st
fish
bash
vi ~/.bash_history
ls
#!/bin/bash
COMP_WORDS=($COMP_LINE)
if [ "${COMP_LINE: -1}" = " " ]; then   COMP_WORDS+=(""); fi
COMP_CWORD=$((${#COMP_WORDS[@]} - 1))
COMP_POINT=${#COMP_LINE}
# bash-completions
[ -f /data/data/com.termux/files/usr/share/bash-completion/bash_completion ] && source /data/data/com.termux/files/usr/share/bash-completion/bash_completion # termux
[ -f /usr/local/share/bash-completion/bash_completion ] && source /usr/local/share/bash-completion/bash_completion # osx
[ -f /usr/share/bash-completion/bash_completion ] && source /usr/share/bash-completion/bash_completion # linux
__load_completion "${COMP_WORDS[0]}"
$"$(complete -p "${COMP_WORDS[0]}" | sed -r 's/.* -F ([^ ]+).*/\1/')"
for i in "${COMPREPLY[@]}"; do   if [[ -d "${i}" && "${i}" != */ ]]; then     echo "${i}/";   else     echo "${i}";   fi; done
#!/bin/bash
COMP_WORDS=($COMP_LINE)
if [ "${COMP_LINE: -1}" = " " ]; then   COMP_WORDS+=(""); fi
COMP_CWORD=$((${#COMP_WORDS[@]} - 1))
COMP_POINT=${#COMP_LINE}
# bash-completions
[ -f /data/data/com.termux/files/usr/share/bash-completion/bash_completion ] && source /data/data/com.termux/files/usr/share/bash-completion/bash_completion # termux
[ -f /usr/local/share/bash-completion/bash_completion ] && source /usr/local/share/bash-completion/bash_completion # osx
[ -f /usr/share/bash-completion/bash_completion ] && source /usr/share/bash-completion/bash_completion # linux
__load_completion "${COMP_WORDS[0]}"
$"$(complete -p "${COMP_WORDS[0]}" | sed -r 's/.* -F ([^ ]+).*/\1/')"
for i in "${COMPREPLY[@]}"; do   if [[ -d "${i}" && "${i}" != */ ]]; then     echo "${i}/";   else     echo "${i}";   fi; done

workaround

#~/.config/carapace/bridge/bash/.bashrc
export HISTFILE=/dev/null

carapace version

> carapace --version
1.0.2

configuration

source <(/nix/store/3wrri355w1kdcd5rc0lg2jscq733hyy6-carapace-1.0.2/bin/carapace _carapace bash)

export CARAPACE_BRIDGES='fish,bash,zsh'
export CARAPACE_EXCLUDES='nix'

Look for bash completions in all $XDG_DATA_DIRS

On NixOS, completions are often surfaced to bash (and shells with compatible completers) via $XDG_DATA_DIRS. I tried to use nushell with carapace's bridge to bash enabled, but none of these completions were found, since carapace only looks in the directories listed here.

Contrast this with where bash looks for completions, listed in the bash-completion FAQ:

Q. What is the search order for the completion file of each target command?

A. The completion files of commands are looked up by the shell function
__load_completion. Here, the search order in bash-completion >= 2.12 is
explained.

  1. BASH_COMPLETION_USER_DIR. The subdirectory completions of each paths
    in BASH_COMPLETION_USER_DIR separated by colons is considered for a
    completion directory.
  2. The location of the main bash_completion file. The subdirectory
    completions in the same directory as bash_completion is considered.
  3. The location of the target command. When the real location of the command
    is in the directory <prefix>/bin or <prefix>/sbin, the directory
    <prefix>/share/bash-completion/completions is considered.
  4. XDG_DATA_DIRS (or the system directories /usr/local/share:/usr/share
    if empty). The subdirectory bash-completion/completions of each paths
    in XDG_DATA_DIRS separated by colons is considered.

The completion files of the name <cmd> or <cmd>.bash, where <cmd> is
the name of the target command, are searched in the above completion
directories in order. The file that is found first is used. When no
completion file is found in any completion directories in this process, the
completion files of the name _<cmd> is next searched in the completion
directories in order.

The relevant code in the bashrc file is here.

It would be great if carapace could look in all of these directories as well. I'm not familiar with go, otherwise I'd just directly submit a PR. Do you have time to look into this? Otherwise I might try to figure this out myself some time later, and submit a PR, but that could take a while.

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.