aboutsummaryrefslogtreecommitdiffhomepage
path: root/home-manager/config/fish/config.fish
blob: 0d605ed0b6537b7d7ee49f214366f662bff4771b (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
set -l has_nvim (type -q nvim)
set -l has_fd (type -q fd)
set -l on_darwin (test (uname) = "Darwin")

function fish_greeting; end

# Abbreviations
abbr -a direnvnix 'nix flake new -t github:nix-community/nix-direnv'
abbr -a g 'git'
abbr -a gs 'git s'
abbr -a ll 'ls -l'
abbr -a lla 'ls -la'
abbr -a lsa 'ls -a'
abbr -a lsal 'ls -la'
abbr -a lsl 'ls -l'

# Aliases
alias cat 'bat'
alias cp 'cp -i'
alias e 'nvim'
alias grep 'rg'
alias mkdir 'mkdir -p'
alias mv 'mv -i'
alias rm 'rm -i'
alias ssh 'TERM=xterm-256color command ssh'
alias tree 'tree -N --gitignore'
alias view 'nvim -R'
alias vim 'nvim'
alias vimdiff 'nvim -d'

if [ -n $on_darwin ]
    alias tac 'tail -r'
end

# Bindings
function __cd_parent_dir
    if [ -n (commandline) ]
        return
    end
    cd ..
    commandline -f repaint
end
bind \cj __cd_parent_dir

function __cd_prev_dir
    if [ -n (commandline) ]
        return
    end
    cd -
    commandline -f repaint
end
bind \co __cd_prev_dir

function __cd_project_root_dir
    if [ -n (commandline) ]
        return
    end
    if [ (git rev-parse --is-inside-work-tree 2>/dev/null) = 'true' ]
        cd (git rev-parse --show-toplevel)
        commandline -f repaint
    end
end
bind \cg __cd_project_root_dir

bind \cz fg

function 256colors
    for code in (seq 0 255)
        printf '\e[38;05;%dm%3d: Test\n' $code $code
    end
end

function mkcd
    mkdir -p $argv[1]
    cd $argv[1]
end

function pwgen --wraps pwgen
    if [ (count $argv) -gt 0 ]
        command pwgen $argv
    else
        command pwgen -N 1 64
        command pwgen -N 1 48
        command pwgen -N 1 32
        command pwgen -N 1 24
        command pwgen -N 1 16
    end
end

if [ -n $has_nvim ]
    if [ -n $has_fd ]
        set -gx FZF_DEFAULT_COMMAND "fd --type f --strip-cwd-prefix --hidden --exclude .git"
    end
    function ee
        if [ (count $argv) -eq 0 ]
            fzf --reverse --bind 'enter:become(nvim {})'
        else
            find $argv[1] -type f -print0 | fzf --read0 --reverse --bind 'enter:become(nvim {})'
        end
    end
else
    function ee
        if [ (count $argv) -eq 0 ]
            fzf --reverse --bind 'enter:become(vim {})'
        else
            find $argv[1] -type f -print0 | fzf --read0 --reverse --bind 'enter:become(vim {})'
        end
    end
end

function terraform
    set -l subcommand $argv[1]
    if [ $subcommand = "apply" ]
        echo "Are you sure to apply?"
        echo -n "(y/n): "
        read answer
        if [ $answer = "y" ]
            command terraform $argv
        else
            echo "Cancelled."
        end
    else
        command terraform $argv
    end
end