Nushell + fzf — functions for git switch and git branch -d
I’ve recently re-discovered nushell and I’ve fallen hard. I’m committed. I’m stumbling my way through things, of course, but I’ve set my course and am not turning back.
Perhaps one day I’ll blog my reasons, but this post is about two of my most-used zsh functions:
gbs
: a function togit switch
usingfzf
gbd
: a function togit branch -d
usingfzf
I’ve ported them to nushell. Here’s the source, without comment or explanation:
def gbs [] {
let branch = (
git branch |
split row "\n" |
str trim |
where ($it !~ '\*') |
where ($it != '') |
str join (char nl) |
fzf --no-multi
)
if $branch != '' {
git switch $branch
}
}
def gbd [] {
let branches = (
git branch |
split row "\n" |
str trim |
where ($it !~ '\*') |
where ($it != '') |
str join (char nl) |
fzf --multi |
split row "\n" |
where ($it != '')
)
if ($branches | length) > 0 {
$branches | each { |branch| git branch -d $branch }
""
}
}
I put them in my config.nu
. I welcome any feedback.
Edit: tested with nushell 0.78.1, built from source.