From b3eb0f34d13b4daf7a583b40960aa311b9d66f24 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 29 Feb 2024 15:21:05 -0600 Subject: [PATCH] Add Interactively Switch asdf Package Versions as a Unix TIL --- README.md | 3 +- ...eractively-switch-asdf-package-versions.md | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 unix/interactively-switch-asdf-package-versions.md diff --git a/README.md b/README.md index 0265d56..d3facbe 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1383 TILs and counting..._ +_1384 TILs and counting..._ --- @@ -1351,6 +1351,7 @@ _1383 TILs and counting..._ - [Ignore A Directory During ripgrep Search](unix/ignore-a-directory-during-ripgrep-search.md) - [Ignore The Alias When Running A Command](unix/ignore-the-alias-when-running-a-command.md) - [Interactively Browse Available Node Versions](unix/interactively-browse-availabile-node-versions.md) +- [Interactively Switch asdf Package Versions](unix/interactively-switch-asdf-package-versions.md) - [Jump To The Ends Of Your Shell History](unix/jump-to-the-ends-of-your-shell-history.md) - [Kill Everything Running On A Certain Port](unix/kill-everything-running-on-a-certain-port.md) - [Killing A Frozen SSH Session](unix/killing-a-frozen-ssh-session.md) diff --git a/unix/interactively-switch-asdf-package-versions.md b/unix/interactively-switch-asdf-package-versions.md new file mode 100644 index 0000000..a073089 --- /dev/null +++ b/unix/interactively-switch-asdf-package-versions.md @@ -0,0 +1,30 @@ +# Interactively Switch asdf Package Versions + +I use [`asdf`](https://asdf-vm.com/) to manage versions for a couple different +languages that I use across projects. I mostly use it for `node` and `ruby`. + +When setting up a new project or needing to set the version for an existing +one, I run some version of: + +```bash +$ asdf local nodejs +``` + +But before I can do that, I need to figure out what versions I have installed +(`asdf list nodejs`), so I end up running two commands and having to remember +the nuances of the sub-commands for each. + +I decided to make this small interaction easier by making it _interactive_ with +[`fzf`](https://github.com/junegunn/fzf). + +```bash +asdf local nodejs $( + asdf list nodejs | fzf | xargs | sed 's/^\*//' +) +``` + +This grabs the list of installed `nodejs` versions, turns it into an +interactive list with `fzf`, and then passes my selection to `asdf local` to +set that version. + +I can substitute `ruby` for `nodejs` to do the same thing for Ruby versions.