warpdotdev / Warp

Warp is a modern, Rust-based terminal with AI built in so you and your team can build great software, faster.
https://warp.dev
Other
20.77k stars 348 forks source link

Support aliases that are loaded after Warp has bootstrapped #554

Open Tirke opened 2 years ago

Tirke commented 2 years ago

Describe the bug

I saw #63 but I'm still not getting aliases completions.
I'm running `zinit` with `oh-my-zsh` style aliases.

Inputting `gco` TAB is not providing any useful completions apart from files in the current directory

To Reproduce

Steps to reproduce:

  1. Install and use zinit
  2. Install oh-my-zsh git plugin zinit wait lucid for OMZP::git
  3. Input gco in Wrap and press TAB

Expected behaviour

Should output completions for git aliases

Screenshots

No response

Operating System

MacOS

OS Version

12.1

Additional context

No response

elviskahoro commented 2 years ago

@Tirke The completions options in the menu are all built natively. They're working fine on my end. (aliases are being pulled properly from my gitrc) It's likely a compatibility issue with some of your zsh plugins. Try this advice from our docs

Use a warp flag to disable some of your zsh plugins just for Warp

if [[ $TERM_PROGRAM != "WarpTerminal" ]]; then
##### WHAT YOU WANT TO DISABLE FOR WARP - BELOW

    # POWERLEVEL10K
    # OH-MY-ZSH-THEMES
    # OH-MY-ZSH-PLUGINS
    # FIG
    # BIND keys like:
    # bindkey "^j" down-line-or-beginning-search
    # [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && 
    # . "/usr/local/etc/profile.d/bash_completion.sh"
    # eval "$(rbenv init -)"

##### WHAT YOU WANT TO DISABLE FOR WARP - ABOVE
fi
elviskahoro commented 2 years ago

This is my alias section from my git config for reference:

[alias]
    a = add
    af = "!git add $(find . -type f -maxdepth 1)"
    au = add -u
    aa = add --all
    bc = checkout -b
    bd = branch -D
    bl = branch
    bla = branch -a
    bm = branch --merged
    bn = branch --no-merged
    ch = checkout
    ca = commit --amend --no-edit
    cm = commit -m
    co = commit
    cp = commit -p
    d = "!f() { if [ $# -eq 0 ]; then git diff; else git diff HEAD~$1; fi }; f"
    dc = diff --staged
    df = "!f() { if [ $# -eq 0 ]; then git diff-tree --no-commit-id --name-status -r HEAD; else git diff-tree --no-commit-id --name-status -r HEAD~$1; fi }; f"
    x = checkout - 
    l = log --oneline
    m = checkout main
    p = checkout HEAD^1
    pf = "!git push origin HEAD"
    pb = "!git push -u origin $(git branch-name)"
    pbd = "!git push origin :$(git branch-name)"
    pl = pull
    pu = push
    r = "!f() { if [ $# -eq 0 ]; then git reset --mixed; else git reset HEAD~$1 --mixed; fi }; f"
    rba = rebase --abort
    rbm = rebase main
    rbc = rebase --continue
    s = status
    sw = switch
    sh = "!f() { if [ $# -eq 0 ]; then git show; else git show HEAD~$1; fi }; f"
    sq = "!f() { if [ $# -gt 2 ]; then echo "must be more than one"; else git rebase -i HEAD~$1; fi }; f"
    st = stash --patch
    sta = stash
    stau = stash --include-untracked
    std = stash drop
    stl = stash list
    stp = stash pop
    sts = stash show
    um = pull origin main

    si = submodule init
    su = submodule update
    sur = submodule update --init --recursive
    smain = submodule foreach --recursive "git checkout main"
    spull = submodule foreach --recursive "git pull"
    spush = "!f() { if [ $# -eq 0 ]; then git submodule foreach --recursive "git add ."; git submodule foreach --recursive "git commit -m c"; git push --recurse-submodules=on-demand; else git submodule foreach --recursive "git add ."; git submodule foreach --recursive "git commit -m $1"; git push --recurse-submodules=on-demand; fi } f"
    sstash = submodule foreach --recursive "git stash"
    # caa = commit -a --amend -C HEAD
    # sba = "!f() { git subtree add --prefix $2 $1 master --squash; }; f"
    # bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs -r git branch -d; }; f"
    # new = !sh -c 'git log $1@{1}..$1@{0} "$@"'
    # sortdiff = !sh -c 'git diff "$@" | grep "^[+-]" | sort --key=1.2 | uniq -u -s1'
    # lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
    # lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
elviskahoro commented 2 years ago

Not sure where the random tabs came from

elviskahoro commented 2 years ago

Here's my email: elvis@warp.dev

I can help you look at more closely if the Terminal Flag doesn't fix it.

Tirke commented 2 years ago

@elviskahoro Thanks for answering. zinit is quite an opinionated and elegant (for me at least) way to handle zsh configs. I'm not using git aliases I'm using bash aliases for git and they don't autocomplete. Here is my .zshrc


### Added by Zinit's installer
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
    print -P "%F{33}▓▒░ %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
    command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
    command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
        print -P "%F{33}▓▒░ %F{34}Installation successful.%f%b" || \
        print -P "%F{160}▓▒░ The clone has failed.%f%b"
fi

source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit

# Load a few important annexes, without Turbo
# (this is currently required for annexes)
zinit light-mode for \
    zdharma-continuum/zinit-annex-rust \
    zdharma-continuum/zinit-annex-as-monitor \
    zdharma-continuum/zinit-annex-patch-dl \
    zdharma-continuum/zinit-annex-bin-gem-node

### End of Zinit's installer chunk

fpath+=( /usr/local/share/zsh/site-functions /opt/homebrew/share/zsh/site-functions )
path+=( $HOME/go/bin $HOME/.cargo/bin $HOME/.yarn/bin )

zinit lucid for \
    atinit"HIST_STAMPS=dd.mm.yyyy" \
    OMZL::history.zsh \
    light-mode pick"async.zsh" src"pure.zsh" \
                sindresorhus/pure

zinit wait lucid for \
    OMZL::completion.zsh \
    atload"
        alias ..='cd ..'
        alias ...='cd ../..'
        alias ....='cd ../../..'
        alias .....='cd ../../../..'
        alias l='ls -lahG'
        alias tf='terraform'    
        export LSCOLORS='Exfxcxdxbxegedabagacad'
        export AWS_DEFAULT_REGION=eu-central-1
        eval '$(fnm env)'        
    " \
    OMZL::directories.zsh \
    OMZL::git.zsh \
    OMZP::brew \
    OMZP::git \
    OMZL::spectrum.zsh \
    OMZL::termsupport.zsh \
    agkozak/zsh-z \

zinit wait lucid for \
    atinit"zicompinit; zicdreplay" \
    zdharma-continuum/fast-syntax-highlighting \
    atload"_zsh_autosuggest_start" \
    zsh-users/zsh-autosuggestions \
    atload'bindkey "^[[A" history-substring-search-up;
        bindkey "^[[B" history-substring-search-down' \
    zsh-users/zsh-history-substring-search \
    zdharma-continuum/history-search-multi-word \
    blockf atpull'zinit creinstall -q .' \
    zsh-users/zsh-completions

The aliases are coming from the OMZP::git meaning I end up with this file https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/git.plugin.zsh loaded into this path ~/.zinit/snippets/OMZP::git/OMZP::git and it ends up defining all my aliases.

Wrap is not autocompleting those 😞 I don't really want to use a flag to remove things from my config unless i get the same thing natively from Wrap. I got a few colleagues into Wrap and some of them are using oh-my-zsh and they have no issue with their git bash aliases autocompleting. Is it more clear?

elviskahoro commented 2 years ago

CCing @alokedesai

Bobronium commented 2 years ago

@Tirke, @elviskahoro I think the issue here is that zinit wait is used to load some plugins (including OMZP::git that provides completions that you're looking for), so they end up being loaded after shell is started.

My guess is that Warp checks for loaded aliases/plugins/etc. (?) once at startup and ignores anything that happens after.

Upd. Yep, just checked that theory. If I remove wait from my config, warp indeed picks up on loaded aliases.

wait is essential part of what makes zinit so appealing: it allows to do all heavy lifting after prompt is started, so plugins do not affect startup time.

elviskahoro commented 2 years ago

Hey @Bobronium thanks a lot for looking into this. I'll try to loop in someone from our team who's more familiar. But my understanding of the situation is that Warp:

  1. loads RC files manually
  2. we rely on temporal assumptions regularly especially to enable Blocks
  3. will likely have a built in prompt solution, there are some mocks of this here: https://twitter.com/warpdotdev/status/1496263490491023362
alokedesai commented 2 years ago

Hey @Bobronium, thanks for flagging. You are correct that this is an issue in Warp if aliases are loaded after the shell starts. I've added this to our internal tracker for completions improvements, I hope to get to this issue this quarter. I'll post an update as soon as I have one

dannyneira commented 1 year ago

As per duplicate issue #3158: oh-my-zsh plugin: plugins=(git node npm) and aliases: glols & glola don't work in Warp aswell.

shin-sforzando commented 1 year ago

I got the same problem on Zsh 5.9, but it is a little strange behavior. Screenshot 2023-08-06 at 17 23 49 repos is defined as ghq list | fzf --preview 'bat --color=always --style=header,grid --line-range :80 ~/Workspace/{}/README.*', which when executed will cause a parenthesis-related error. But another alias using repos (ex. repo is defined as cd $(ghq root)/$(repos)) works fine. I have confirmed that repos also works fine if the alias expansion is turned off. From these facts, I infer that a syntactic error has occurred when expanding.