summaryrefslogtreecommitdiff
path: root/config/essentials/zsh/functions.zsh
blob: a73ea159d242d2d18a9fda02651e0177086624da (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/zsh

vmp() {
    col -b | \
    vim -MR \
    -c 'set ft=man nolist nonu nornu'
}
vimh() { vim -c "help $1" -c 'call feedkeys("\<c-w>o")' }

nnn() { test -z "$NNNLVL" && /usr/bin/nnn "$@" || exit }
ranger() { test -z "$RANGER_LEVEL" && /usr/bin/ranger "$@" || exit }

# googoo
o ()
{
	f="$(fzffile $1)"
	test "$#" -gt 0 && shift
	test -n "$f" && $EDITOR $@ "$f"
}
go ()
{
	d="$(fzfdir $1)"
	test -d "$d" && cd "$d"
}
ogo ()
{
	d="$(fzfdirfile $1)"
	test -d "$d" && cd "$d"
}

ipc () 
{
   if [[ "$(ip link show eno1 | awk -F, 'NR=1 {print $3}')" == "UP" ]]
   then
        doas ip link set eno1 down
    else
        doas ip link set eno1 up 
   fi
}

calc () { echo "$@" | bc -l }

unique () {
	f="/tmp/$(uuidgen)"
	awk '!x[$0]++' "$1" > "$f"
	mv "$f" "$1"
}

clip () { echo -n "$@" | xclip -selection clipboard -rmlastnl }

fzh () {
    choice="$(tac $HOME/.config/zsh/histfile | fzf)"
    test -z "${choice}" && return
    echo "${choice}" >> "${HOME}/.config/zsh/histfile"
    eval "${choice}"
}

unzipp () {
    file=$1
    shift
    unzip $file $@ || exit 1
    rm $file
}

# fix long waiting time
__git_files () { 
    _wanted files expl 'local files' _files     
}

# allows changing to parent dir of file
function cd () {
    if (( ${#argv} == 1 )) && [[ -f ${1} ]]; then
        [[ ! -e ${1:h} ]] && return 1
        print "Correcting ${1} to ${1:h}"
        builtin cd ${1:h}
    else
        builtin cd "$@"
    fi
}