m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-15 23:03:47 -05:00

Add fuzzy conda activate with python version display and conda tree leaves preview

Paul-Aime
2023-01-26 16:46:50 +01:00
parent 72e7388484
commit 562e49a27a

@@ -23,6 +23,7 @@ Table of Contents
* [Homebrew Cask](#homebrew-cask) * [Homebrew Cask](#homebrew-cask)
* [DNF](#dnf) * [DNF](#dnf)
* [Flatpak](#flatpak) * [Flatpak](#flatpak)
* [Conda](#conda)
* Filesystem navigation * Filesystem navigation
* [Opening files](#opening-files) * [Opening files](#opening-files)
* [Changing directory](#changing-directory) * [Changing directory](#changing-directory)
@@ -1517,6 +1518,46 @@ bindkey '^[f^[u' fzf-flatpak-uninstall-widget #alt-f + alt-u
zle -N fzf-flatpak-uninstall-widget zle -N fzf-flatpak-uninstall-widget
``` ```
### Conda
#### conda-activate (for bash)
Fuzzy conda environment selection with python version display and `conda tree leaves` preview.
![image](https://user-images.githubusercontent.com/36678697/214879546-32e7c184-3a82-4660-9baa-ea73deff5127.png)
```sh
fzf-conda-activate () {
choice=(
$(
conda env list |
sed 's/\*/ /;1,2d' |
xargs -I {} bash -c '
name_path=( {} );
py_version=( $(${name_path[1]}/bin/python --version) );
echo ${name_path[0]} ${py_version[1]} ${name_path[1]}
' |
column -t |
fzf --layout=reverse \
--info=inline \
--border=rounded \
--height=40 \
--preview-window="right:30%" \
--preview-label=" conda tree leaves " \
--preview=$'
line="{}";
line_arr=(${line:1:-1});
env_prefix="${line_arr[2]}";
conda tree -p "$env_prefix" leaves |
perl -F\'[^\\w-_]\' -lae \'print for grep /./, @F;\' |
sort
'
)
)
[[ -n "$choice" ]] && conda activate "$choice"
}
```
### v ### v
#### Inspired by [v](https://github.com/rupa/v). Opens files in ~/.viminfo #### Inspired by [v](https://github.com/rupa/v). Opens files in ~/.viminfo