aboutsummaryrefslogtreecommitdiffstats
path: root/zshenv
blob: 4b699fdffa039c17e0a5fa2b3f8e5ac919b73358 (plain) (blame)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*- mode: sh -*-

# Locale
if [[ "$OSTYPE" == darwin* ]]; then
    export LANG="en_US.UTF-8"
    # iTerm may choose to set an invalid LC_CTYPE
    # https://superuser.com/a/1400419
    export LC_CTYPE="en_US.UTF-8"
    # Norwegian time locale
    export LC_TIME="no_NO.UTF-8"
    # Ensure that /etc/zprofile does not mess with our PATH
    unsetopt GLOBAL_RCS
elif [[ "$OSTYPE" == linux* ]]; then
    export LANG="en_US.UTF-8"
    # Norwegian locale on Linux is named differently
    export LC_TIME="nb_NO.UTF-8"
fi

# Set TERM
case "$TERM" in
    xterm*)
        export TERM="xterm-256color"
        ;;
    screen*|tmux*)
        # OS may lack terminfo entry for tmux-256color
        # https://github.com/tmux/tmux/issues/2262
        export TERM="screen-256color"
        ;;
esac

# Homebrew
if [[ -x "/usr/local/bin/brew" ]]; then
    eval "$(/usr/local/bin/brew shellenv)"
elif [[ -x "/opt/homebrew/bin/brew" ]]; then
    eval "$(/opt/homebrew/bin/brew shellenv)"
fi
if (( $+commands[brew] )); then
    export HOMEBREW_NO_ANALYTICS=1
    export HOMEBREW_NO_AUTO_UPDATE=1
fi

# Set PATH
function path-prepend {
    [[ -d "$1" ]] && path[1,0]=($1)
}
function path-append {
    [[ -d "$1" ]] && path+=($1)
}
path-prepend "/usr/local/sbin"
path-prepend "/usr/local/bin"
path-prepend "/Library/TeX/texbin"
path-prepend "/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/bin"
path-prepend "$HOME/.local/bin"
path-prepend "$HOME/.cargo/bin"

# Set CDPATH
function cdpath-append {
    [[ -d "$1" ]] && cdpath+=($1)
}
cdpath-append "$HOME"
cdpath-append "$HOME/p"

# Pager
if (( $+commands[less] )); then
    export LESS="-Ri"
    export PAGER="less"
    # Add colors to man pages
    export LESS_TERMCAP_mb=$'\e[1;32m'      # Begins blinking.
    export LESS_TERMCAP_md=$'\e[1;32m'      # Begins bold.
    export LESS_TERMCAP_me=$'\e[0m'         # Ends mode.
    export LESS_TERMCAP_se=$'\e[0m'         # Ends standout-mode.
    export LESS_TERMCAP_so=$'\e[1;31m'      # Begins standout-mode.
    export LESS_TERMCAP_ue=$'\e[0m'         # Ends underline.
    export LESS_TERMCAP_us=$'\e[4m'         # Begins underline.
fi

# Set EDITOR, from most to least preferred
if (( $+commands[emacsclient] )); then
    export EDITOR="emacsclient"
elif (( $+commands[emacs] )); then
    export EDITOR="emacs"
elif (( $+commands[mg] )); then
    export EDITOR="mg"
elif (( $+commands[jmacs] )); then
    export EDITOR="jmacs"
elif (( $+commands[vim] )); then
    export EDITOR="vim"
elif (( $+commands[vi] )); then
    export EDITOR="vi"
fi

# Set LS_COLORS
if (( $+commands[gdircolors] )); then
    eval "$(gdircolors -b)"
elif (( $+commands[dircolors] )); then
    eval "$(dircolors -b)"
fi

# Use bfs as find command in fzf
if (( $+commands[fzf] && $+commands[bfs] )); then
    export FZF_DEFAULT_COMMAND="bfs"
    export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
fi

# Remove mosh prefix from terminal title
(( $+commands[mosh] )) && export MOSH_TITLE_NOPREFIX=1

# Kill mosh-server if it has been inactive for a week
(( $+commands[mosh-server] )) && export MOSH_SERVER_NETWORK_TMOUT=604800

# GOPATH
if [[ -d "${HOME}/go" ]]; then
    export GOPATH="${HOME}/go"
    path-prepend "${GOPATH}/bin"
fi

# JAVA_HOME
java_home="$(/usr/libexec/java_home 2> /dev/null)"
[[ -n "$java_home" ]] && export JAVA_HOME="$java_home"
unset java_home

# MAVEN_OPTS
# Prevent Maven from running tasks in the foreground
(( $+commands[mvn] )) && export MAVEN_OPTS="-Djava.awt.headless=true"

# PLAN9
if [[ -d "$HOME/.local/plan9" ]]; then
    export PLAN9="$HOME/.local/plan9"
    path-append "$PLAN9/bin"
fi

# Local environment
source "$HOME/.zshenv.local" 2> /dev/null

# Ensure path and cdpath do not contain duplicates
typeset -gU path cdpath

# Clean up functions
unfunction path-prepend cdpath-append