aboutsummaryrefslogtreecommitdiff
path: root/.functions
blob: 33d3e0e1866006b7712f7dd4376d9f44e63e1570 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash

fco () {
    local tags branches target
    branches=$(
        git --no-pager branch --all \
            --format="%(if)%(HEAD)%(then)%(else)%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)%1B[0;34;1mbranch%09%1B[m%(refname:short)%(end)%(end)" \
        | sed '/^$/d'
    ) || return
    tags=$(
        git --no-pager tag | awk '{print "\x1b[35;1mtag\x1b[m\t" $1}'
    ) || return
    target=$(
        (echo $branches; echo $tags) \
        | fzf --no-hscroll --no-multi -n 2 --ansi
    ) || return
    git checkout $(awk '{print $2}' <<<$target)
}

fs () {
    local session
    session=$(tmux list-sessions -F "#{session_name}" \
        | fzf --query=$1 --select-1 --exit-0) \
        && tmux switch-client -t $session
}

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."
}

open () {
    if [ -f /usr/bin/xdg-open ]; then
        nohup xdg-open "$*" > /dev/null 2>&1 &
    elif [ -f /usr/bin/open ]; then
        /usr/bin/open "$*"
    else
        echo "No usable program is found"
    fi
}