Skip to content

Instantly share code, notes, and snippets.

View mikiyaf's full-sized avatar

mikiyaf mikiyaf

View GitHub Profile
@mikiyaf
mikiyaf / fdocker.zsh
Last active April 10, 2018 10:00
docker + fzf
fdocker() {
local dhelp=$(docker --list)
}
@mikiyaf
mikiyaf / mru.zsh
Created November 13, 2017 01:31
mru(mru+fzf) : mru incremental search by fzf, and execute vim, less, ...
mru() {
local -a f
f=(
~/.vim_mru_files(N)
~/.unite/file_mru(N)
~/.cache/ctrlp/mru/cache.txt(N)
~/.frill(N)
)
if [[ $#f -eq 0 ]]; then
echo "There is no available MRU Vim plugins" >&2
@mikiyaf
mikiyaf / frepo.zsh
Last active November 13, 2017 01:26
frepo(ghq+fzf) : incremental search for ghq repo and change directory
frepo() {
local dir
dir=$(ghq list > /dev/null | fzf-tmux --reverse +m) &&
cd $(ghq root)/$dir
}
@mikiyaf
mikiyaf / fkill.zsh
Created November 13, 2017 01:22
fkill - kill process
fkill() {
local pid
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -${1:-9}
fi
}
@mikiyaf
mikiyaf / fh.zsh
Created November 13, 2017 01:20
fh - repeat history
fh() {
print -z $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | sed 's/ *[0-9]* *//')
}
@mikiyaf
mikiyaf / tm.zsh
Created November 13, 2017 01:17
tm - create new tmux session, or switch to existing one
tm() {
[[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
if [ $1 ]; then
tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return
fi
session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux $change -t "$session" || echo "No sessions found."
}
# fs [FUZZY PATTERN] - Select selected tmux session
# - Bypass fuzzy finder if there's only one match (--select-1)
@mikiyaf
mikiyaf / fco.zsh
Created November 13, 2017 01:13
fco - checkout git branch/tag
fco() {
local tags branches target
tags=$(
git tag | awk '{print "\x1b[31;1mtag\x1b[m\t" $1}') || return
branches=$(
git branch --all | grep -v HEAD |
sed "s/.* //" | sed "s#remotes/[^/]*/##" |
sort -u | awk '{print "\x1b[34;1mbranch\x1b[m\t" $1}') || return
target=$(
(echo "$tags"; echo "$branches") |
@mikiyaf
mikiyaf / fshow.zsh
Created November 13, 2017 01:09
fshow - git commit browser (enter for show, ctrl-d for diff)
fshow() {
local out shas sha q k
while out=$(
git log --graph --color=always \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
fzf --ansi --multi --no-sort --reverse --query="$q" \
--print-query --expect=ctrl-d); do
q=$(head -1 <<< "$out")
k=$(head -2 <<< "$out" | tail -1)
shas=$(sed '1,2d;s/^[^a-z0-9]*//;/^$/d' <<< "$out" | awk '{print $1}')
@mikiyaf
mikiyaf / fbr.zsh
Last active November 13, 2017 00:59
fbr - checkout git branch (including remote branches), sorted by most recent commit, limit 30 Last branches
fbr() {
local branches branch
branches=$(git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format="%(refname:short)") &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}