Skip to content

Commit

Permalink
Import zsh aliases for git branch handling into nushell
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Jun 15, 2023
1 parent 14eb837 commit ec5b18d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .config/nushell/config.nu
Original file line number Diff line number Diff line change
Expand Up @@ -650,5 +650,26 @@ let-env config = {
]
}

def git-main-branch [] {
git branch | lines | str replace '^ *(?:\*\s+(.+))?' '$1' | where ($it == "main" or $it == "master") | take 1
}

def git-upstream [] {
git remote | lines | str trim | where ($it == "upstream" or $it == "origin") | reverse | take 1
}

# https://www.nushell.sh/cookbook/git.html#delete-git-merged-branches
def git-delete-merged-branches [] {
git branch --merged | lines | where ($it != "* master" and $it != "* main") | each {|br| git branch -D ($br | str trim) } | str trim
}

def git-switch-default [] {
git switch (git-main-branch)
}

def git-cleanup-branches [] {
git-switch-default; git pull (git-upstream) (git current-branch); git fetch (git-upstream) --tags --prune; git-delete-merged-branches
}

# https://github.com/starship/starship/tree/0cffd59b72adbc4c2c33d6bb14dbca170c775fc4#step-2-setup-your-shell-to-use-starship
source ~/.cache/starship/init.nu
4 changes: 2 additions & 2 deletions home/.aliases.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash

alias git-switch-default='git checkout main 2>/dev/null || git checkout master 2>/dev/null'
alias git-remote-upsteram="git remote | grep -E '^upstream$'|| git remote | grep -E '^origin$'"
alias git-upsteram="git remote | grep -E '^upstream$'|| git remote | grep -E '^origin$'"
# https://github.com/kyanny/git-delete-merged-branches/pull/6
alias git-delete-merged-branches="git branch --merged | grep -vE '((^\*)|^ *(main|master)$)' | xargs -I % git branch -d %"
alias git-cleanup-branches='git-switch-default && git pull $(git-remote-upsteram) $(git current-branch) && git fetch $(git-remote-upsteram) --tags --prune && git-delete-merged-branches'
alias git-cleanup-branches='git-switch-default && git pull $(git-upsteram) $(git current-branch) && git fetch $(git-upsteram) --tags --prune && git-delete-merged-branches'

alias la='exa --long --all --group-directories-first'

Expand Down

0 comments on commit ec5b18d

Please sign in to comment.