all repos — nixfiles @ main

System and user configuration, managed by nix and home-manager

user/settings/fish/per-term/Apple_Terminal.fish (view raw)

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
set window_and_tab 0
set tab 1
set window 2
set document 6
set wd 7

function update_terminal_path --argument-names ps pt
    if set --query SSH_TTY
        printf '\e]%d;file://%s@%s%s\a' $ps $USER (prompt_hostname) \
            (string escape --style=url $pt)
    else
        printf '\e]%d;file://%s\a' $ps (string escape --style=url $pt)
    end
end

function update_terminal_title --argument-names ps pt
    printf '\e]%d;%s\a' $ps $pt
end

function reset_title_document --on-event fish_postexec
    # not _path because we don't want a file:// URL
    update_terminal_title $document ""
end

function reset_title_post_ssh --on-event fish_postexec --argument-names cmdline
    if string match --quiet "ssh *" "$cmdline"
        reset_title_document
        update_terminal_path $wd "$PWD"
        update_terminal_title $window_and_tab ""
    end
end

function set_document_title --on-event fish_preexec --argument-names cmdline
    set --local args (string split ' ' "$cmdline")
    switch "$args[1]"
        case e editor vi vim nvim
            # move options to $argv_opts
            argparse --move-unknown -- $args[2..]

            # check if any arg is a file or directory
            for p in (path filter $argv)
                # set Terminal path to full path of arg
                update_terminal_path $document (path resolve $p)
                return
            end
    end
end

function set_terminal_appearance --description="Set Terminal to use a [light|dark] theme (default=toggle)"
    if test -n "$argv[1]"
        set --function target $argv[1]
    else
        if test $fish_terminal_color_theme = light
            set --function target dark
        else
            set --function target light
        end
    end

    echo Making it $target...
    osascript (status dirname)/set-terminal-theme.applescript $target
end