From 562e49a27abf15fd5874367f9fdf56d1e1beb290 Mon Sep 17 00:00:00 2001 From: Paul-Aime <36678697+Paul-Aime@users.noreply.github.com> Date: Thu, 26 Jan 2023 16:46:50 +0100 Subject: [PATCH] Add fuzzy conda activate with python version display and conda tree leaves preview --- Examples.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Examples.md b/Examples.md index dd71c60..dc659ff 100644 --- a/Examples.md +++ b/Examples.md @@ -23,6 +23,7 @@ Table of Contents * [Homebrew Cask](#homebrew-cask) * [DNF](#dnf) * [Flatpak](#flatpak) + * [Conda](#conda) * Filesystem navigation * [Opening files](#opening-files) * [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 ``` +### 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 #### Inspired by [v](https://github.com/rupa/v). Opens files in ~/.viminfo