aboutsummaryrefslogtreecommitdiff
path: root/profile.dot.link
blob: 80137f372f38e0c2ef7b7e9831ee58080b041f27 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#
# .profile: basic environment setup
#

# Set language
export LC_ALL=pt_BR.UTF-8
export LANG=pt_BR.UTF-8

# Source functions and variables from other places
if [ -e "$HOME/.aliases" ]; then
  . $HOME/.aliases
fi

# Funcoes ZZ
#if [ -e "/usr/bin/funcoeszz" ]; then
#  . /usr/bin/funcoeszz
#fi

# Set PATH
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/games:/usr/local/bin:/usr/local/sbin:/usr/local/games

# Add snap into PATH
if [ -d "/snap/bin" ]; then
  PATH="/snap/bin:$PATH"
fi

# Add ~/.local/bin folder into PATH
if [ -d "$HOME/.local/bin" ]; then
  PATH=$HOME/.local/bin:$PATH
fi

# Add ~/bin folder into PATH
if [ -d "$HOME/bin" ]; then
  PATH=$HOME/bin:$PATH
fi

# Add all ~/apps folders into PATH
if [ -d "$HOME/apps" ]; then
  PATH=$HOME/apps:$PATH

  for folder in `ls $HOME/apps`; do
    PATH=$HOME/apps/$folder:$PATH
  done
fi

# Add all ~/apps/local folders into PATH
if [ -d "$HOME/apps/local" ]; then
  for folder in `ls $HOME/apps/local`; do
    PATH=$HOME/apps/local/$folder:$PATH
  done
fi

# PATH for stowpkg
if [ -d "$HOME/apps/stowpkg/tree/`uname -m`/bin" ]; then
  PATH="$HOME/apps/stowpkg/tree/`uname -m`/bin:$PATH"
fi

# Add /vagrant into PATH, useful if we're inside a virtual machine
if [ -d "/vagrant/bin" ]; then
  PATH="/vagrant/bin:/vagrant:$PATH"
fi

# Add /srv/kvmx into PATH, useful if we're inside a virtual machine
if [ -d "/srv/kvmx/bin" ]; then
  PATH="/srv/kvmx/bin:/srv/kvmx:$PATH"
fi

# Add /srv/shared into PATH, useful if we're inside a virtual machine
if [ -d "/srv/shared/bin" ]; then
  PATH="/srv/shared/bin:/srv/shared:$PATH"
fi

# Add composer into PATH
if [ -d "$HOME/.composer/vendor/bin" ]; then
  PATH="$HOME/.composer/vendor/bin:$PATH"
fi

# Export PATH
export PATH=$PATH

# Where most projects live
# Use $HOME instead of ~ for zsh compatibility
#export WORKPATH="$HOME/file:$HOME/data:$HOME/code:$HOME/apps:$HOME/.dotfiles:$HOME/.dotfiles/modules"
export WORKPATH="$HOME/file:$HOME/data:$HOME/code:$HOME/apps:$HOME/apps/dotfiles/modules"

# See http://www.caliban.org/bash/#bashtips
export CDPATH=".:$HOME:$WORKPATH"

# Expand workpath
#for folder in `echo $WORKPATH | sed -e "s|:| |g" -e "s|~|$HOME|g"`; do
#  PROJECTS="$PROJECTS`ls -d $folder/*`"
#done

# Based on http://superuser.com/questions/90535/how-do-i-turn-of-auto-echo-in-bash-when-i-cd
if [ "$0" = "bash" ]; then
  cd() {
    if [ -z "$*" ]; then
      destination=~
    else
      destination=$*
    fi

    # Check if its a project under CPATH
    cdpath=`command cd "${destination}" 2> /dev/null`

    # Got to folder
    command cd "${destination}" > /dev/null

    # Update screen title
    #
    # Doesn't deal about getting out of a project path
    # or if going into a project subfolder
    #
    #if [ ! -z "$cdpath" ] && [ ! -z "$STY" ]; then
    #  folder="`basename $cdpath`"
    #
    #  if echo "$PROJECTS" | grep -q "/$folder$"; then
    #    # Got inside a project folder
    #    stitle `basename $folder`
    #  fi
    #fi
  }
fi

# Special cd: change folder and set title
scd() {
  cd "$*"
  stitle `basename $*` > /dev/null 2>&1
  ttitle `basename $*` > /dev/null 2>&1
}

mkday() {
  suffix="$1"
  folder="`today`"

  if [ ! -z "$suffix" ]; then
    folder="$folder-$suffix"
  fi

  mkdir $folder && cd $folder
}

mkmonth() {
  suffix="$1"
  folder="`month`"

  if [ ! -z "$suffix" ]; then
    folder="$folder-$suffix"
  fi

  mkdir $folder && cd $folder
}

mkcd() {
  mkdir "$*" && cd "$*"
}

mktouch() {
  mkdir -p `dirname "$*"`
  touch "$*"
}

# Default editor
#if [ ! -z "$DISPLAY" ]; then
#  # Avoid "Avoiding protocol specified" error
#  export EDITOR="vim -X"
#else
#  export EDITOR="vim"
#fi
export EDITOR="vim"

# Basic git configuration
# See http://stackoverflow.com/questions/4192014/git-ps1-extremely-slow-in-kernel-tree
export GIT_PS1_SHOWDIRTYSTATE=""
export GIT_PS1_SHOWUNTRACKEDFILES=""

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ ! -z "$BASH" ]; then
  if ! shopt -oq posix; then
    if [ -f /usr/share/bash-completion/bash_completion ]; then
      . /usr/share/bash-completion/bash_completion
    elif [ -f /etc/bash_completion ]; then
      . /etc/bash_completion
    fi
  fi
fi

# Load git completion if needed
#if [ ! -z "$BASH" ]; then
#  if ! type __git_ps1 2> /dev/null | head -1 | grep -q function; then
#    if [ -e "/etc/bash_completion.d/git-prompt" ]; then
#      . /etc/bash_completion.d/git-prompt
#    elif [ -e "/etc/bash_completion.d/git" ]; then
#      . /etc/bash_completion.d/git
#    fi
#  fi
#fi

# Less configuration
# See http://seclists.org/fulldisclosure/2014/Nov/74
export LESSSECURE="1"
export LESSOPEN=""
export LESSCLOSE=""

# Lynx configuration
export LYNX_LSS="$HOME/.lynx/lynx.lss"
export LYNX_CFG="$HOME/.lynx/lynx.cfg"

# Temporary folder
export TMPDIR="$HOME/temp/misc"
export TMP="$HOME/temp/misc"
# This might cause issues when trying to attach to remote tmux sessions
#export TMUX_TMPDIR="$TMP/misc"
mkdir -p $TMP

# Log folder
export LOG="$HOME/temp/log"
mkdir -p $LOG

# Dir colors
eval "`dircolors -b ~/.dircolorsrc`"

# SSH and GPG Agents
if [ -x "$HOME/apps/utils-ssh/ssh-agent-loadkeys" ]; then
  . $HOME/apps/utils-ssh/ssh-agent-loadkeys
fi

#if [ -e "$HOME/apps/utils-ssh/ssh-agent-eval" ]; then
#  $HOME/apps/utils-ssh/ssh-agent-eval
#fi

# GPG Agent
#if [ -e "$HOME/apps/utils-gpg/gpg-agent-eval" ]; then
#  $HOME/apps/utils-gpg/gpg-agent-eval
#fi

# Remove lost found folder if empty
if [ -d "$HOME/lost+found" ]; then
  rmdir $HOME/lost+found &> /dev/null
fi

# Make sure basic folder structure exists
mkdir -p $HOME/apps $HOME/file $HOME/mail $HOME/sync $HOME/temp/public

# Make sure data symlink exists
if [ -e "/var/data" ] && [ ! -e "$HOME/data" ]; then
  ln -s /var/data $HOME/data
fi

# Make sure code symlink exists
if [ -e "/var/data/code" ] && [ ! -e "$HOME/code" ]; then
  ln -s /var/data/code $HOME/code
fi

# Make sure download symlink exists
if [ -e "/var/data/load" ] && [ ! -e "$HOME/load" ]; then
  ln -s /var/data/load $HOME/load
elif [ ! -e "$HOME/load" ]; then
  mkdir -p $HOME/load
fi

# Custom configuration
if [ -e "$HOME/.custom/profile" ]; then
  . $HOME/.custom/profile
fi

# Python
if [ -e "$HOME/apps/python" ]; then
  export PYTHONPATH="$HOME/apps/python"

  if [ -e "$HOME/apps/python/venv/bin/activate" ]; then
    source $HOME/apps/python/venv/bin/activate
  fi
fi

# Start the powerline daemon
# See http://powerline.readthedocs.io/en/master/usage/shell-prompts.html
if [ -x "/usr/bin/powerline-daemon" ]; then
  /usr/bin/powerline-daemon -q
fi

# Bash specifics
#if [ -n "$BASH_VERSION" ]; then
if [ "$0" = "bash" ]; then
  # Command prompt if no system-wide custom prompt is available
  if [ "$TERM" != "linux" ] && [ -e "/usr/share/powerline/bindings/bash/powerline.sh" ]; then
    powerline-daemon -q
    POWERLINE_BASH_CONTINUATION=1
    POWERLINE_BASH_SELECT=1
    . /usr/share/powerline/bindings/bash/powerline.sh
  elif ! type command_prompt &> /dev/null && [ -e "$HOME/apps/shellprompt/prompt" ]; then
    . $HOME/apps/shellprompt/prompt
  fi
fi

# Avoid Enter SOCKS5 password for user@127.0.0.1 when using ssh+tor
export SOCKS5_PASSWORD=""

# Detect if we're inside a vagrant VM
if [ -z "$STARTUP_FOLDER" ] && [ -d "/vagrant" ]; then
  STARTUP_FOLDER="/vagrant"
fi

# Detect if we're inside a kvmx VM, old convention
if [ -z "$STARTUP_FOLDER" ] && [ -f "/srv/kvmx/kvmxfile" ]; then
  STARTUP_FOLDER="/srv/kvmx"
fi

# Detect if we're inside a kvmx VM
if [ -z "$STARTUP_FOLDER" ] && [ -f "/srv/shared/kvmxfile" ]; then
  STARTUP_FOLDER="/srv/shared"
fi

# Make sure we start at the startup folder, defaulting to home
cd $STARTUP_FOLDER

# Run startup commands
#if [ ! -z "$STARTUP" ]; then
#  $STARTUP
#fi