Last active
November 28, 2023 08:40
Revisions
-
vendethiel revised this gist
Nov 28, 2023 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ def s [match?: string] { if ($match == null) { git rev-parse --abbrev-ref HEAD | str trim } else { let $branches = git branch | grep -i $match | tr '*' ' ' | lines | str trim let $length = $branches | length if ($length == 0) { "No branch found with hint" } else if ($length == 1) { git checkout $branches.0 } else if ($branches | any {|b| $b == $match}) { git checkout $match } else { git checkout ($branches | to text | gum filter --placeholder "Several branches matched. Pick the one you want.") } } } -
vendethiel created this gist
Aug 5, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ s() {( COLOR_RED="\u001b[31m" COLOR_RESET="\u001b[0m" set -e if [[ $# -gt 1 ]] then echo "${COLOR_RED}s accepts 0 or 1 argument${COLOR_RESET}" exit fi if [[ $# -eq 1 ]] then hint=$1 else hint="DEV-" fi integer occs=$(git branch | grep -i $hint | wc -l) if [[ $occs -eq 0 ]] then echo "${COLOR_RED}s: no match found${COLOR_RESET}" exit elif [[ $occs -eq 1 ]] then branch=$(git branch | grep -i $hint | sed 's/*//' | xargs) # XXX that `xargs` is a hack to trim else branch=$(git branch | grep -i $hint | sed 's/*//' | awk '{print $1}' | gum filter --placeholder "Multiple branch matching, pick one") fi if [[ -z "$branch" ]] then echo "${COLOR_RED}s: no branch selected${COLOR_RESET}" exit fi git checkout $branch )}