Last active
April 25, 2022 12:03
-
-
Save pierpo/7bb75a1736f18389f769e44a8b6efe86 to your computer and use it in GitHub Desktop.
Useful aliases
This file contains 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 characters
############### | |
# Git and fzf # | |
# https://hackernoon.com/be-125-more-efficient-with-git-60556a1ce971#.rnypamia2 | |
[alias] | |
# Starts an interactive rebase by selecting a commit with fzf | |
# "fuzzy rebase" | |
frebase = "!f() { \ | |
git log --pretty=oneline \ | |
| fzf -n 2.. \ | |
| awk '{print $1\"^\"}' \ | |
| xargs -o git rebase --autostash -i; \ | |
}; f" | |
# Starts an interactive rebase by selecting a commit with fzf | |
# using the --onto parameter. Useful to rebase on top of a rebased branch. | |
# "fuzzy rebase onto" | |
# | |
# Usage: git frebase TARGET_BRANCH | |
# then interactively select the first commit of your branch | |
frebaseonto = "!f() { \ | |
git log --pretty=oneline \ | |
| fzf -n 2.. \ | |
| awk '{print $1\"^\"}' \ | |
| xargs -o git rebase --autostash --onto $1; \ | |
}; f" | |
# Amend into a past commit using fzf | |
# Stage your changes `git add -p`, then run `git autofixup` and choose the target commit | |
autofixup = "!f() { \ | |
COMMIT=$(git log --pretty=oneline | fzf | awk '{print $1}'); \ | |
git commit --fixup $COMMIT; \ | |
GIT_SEQUENCE_EDITOR=: git rebase --autostash --autosquash -i $COMMIT^; \ | |
}; f" | |
# Same as autofixup but with --no-verify | |
autofixup = "!f() { \ | |
COMMIT=$(git log --pretty=oneline | fzf | awk '{print $1}'); \ | |
git commit --no-verify --fixup $COMMIT; \ | |
GIT_SEQUENCE_EDITOR=: git rebase --autostash --autosquash -i $COMMIT^; \ | |
}; f" | |
# Lists most recent branches I worked on, and checks out to the selected one | |
# "my-branches fuzzy checkout" | |
myfco = "!f() { git branch -a --sort=-committerdate | grep -v remotes\\/ | fzf | sed 's/remotes\\/origin\\///' | xargs -o git checkout; }; f" |
This file contains 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 characters
# Search the given string in git history | |
# Lists the results using fzf | |
searchgit() { | |
STRING_TO_SEARCH=$1 | |
shift; | |
git log -S"$STRING_TO_SEARCH" --color=always \ | |
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" | | |
fzf --ansi --reverse --tiebreak=index \ | |
--bind "ctrl-m:execute: | |
(grep -o '[a-f0-9]\{7\}' | head -1 | | |
xargs -I % sh -c 'git show --color=always % | less -R') << 'FZF-EOF' | |
{} | |
FZF-EOF | |
" | |
} | |
# Interactively select (using fzf) a docker container to run bash | |
dbash() { | |
CONTAINER=$(docker ps | awk '{print $1, $2}' | awk 'NR > 1' | fzf | awk '{print $1}') | |
if [ ! -z "$CONTAINER" ] | |
then | |
docker exec -it $CONTAINER bash | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment