Skip to content

Instantly share code, notes, and snippets.

@mizukmb
Last active October 31, 2016 07:55
Show Gist options
  • Save mizukmb/cf8c5ab16b647c2ff262bf3804b0c0aa to your computer and use it in GitHub Desktop.
Save mizukmb/cf8c5ab16b647c2ff262bf3804b0c0aa to your computer and use it in GitHub Desktop.
#!/bin/bash
case "$1" in
-a|--all)
git branch --sort=-authordate -v -a | peco | sed -e 's/*/ /' | sed -e 's/ //' | cut -d ' ' -f1 | xargs git checkout
;;
-r|--remotes)
git branch --sort=-authordate -v -r | peco | sed -e 's/*/ /' | sed -e 's/ //' | cut -d ' ' -f1 | xargs git checkout
;;
*)
git branch --sort=-authordate -v | peco | sed -e 's/*/ /' | sed -e 's/ //' | cut -d ' ' -f1 | xargs git checkout
;;
esac
@mizukmb
Copy link
Author

mizukmb commented Oct 27, 2016

depends: peco

@masutaka
Copy link

sed -e 's/*/ /' | sed -e 's/ //'sed -E -e 's/^[* ]+//' で良さそうです(OSX の場合)。さらに重複を減らすとこうなりますね。Bash 記法はないので、Bourne Shell で良さそう。

#!/bin/sh

case "$1" in
  -a|--all)
    OPTS="-a"
    ;;
  -r|--remotes)
    OPTS="-r"
    ;;
  *)
    OPTS=""
    ;;
esac

git branch --sort=-authordate -v $OPTS | peco | sed -E -e 's/^[* ]+//' | cut -d ' ' -f1 | xargs git checkout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment