aboutsummaryrefslogtreecommitdiff
path: root/profile.dot.link
blob: b0626b4076d32ab48f5a24718f03173cdd7d92f3 (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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#
# .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`" ]; then
  if [ -d "$HOME/apps/stowpkg/tree/`uname -m`/bin" ]; then
    PATH="$HOME/apps/stowpkg/tree/`uname -m`/bin:$PATH"
  fi

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

  if [ -d "$HOME/apps/stowpkg/tree/`uname -m`/usr/local/bin" ]; then
    PATH="$HOME/apps/stowpkg/tree/`uname -m`/usr/local/bin:$PATH"
  fi
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

# Add Go into PATH
if [ -e "/usr/lib/go" ]; then
  export GOROOT="/usr/lib/go"

  PATH="$GOROOT/bin:$PATH"
fi

# Add local Go into PATH
if [ -e "$HOME/apps/go" ]; then
  export GOPATH="$HOME/apps/go"

  PATH="$GOPATH/bin:$PATH"
fi

# Add local gems into PATH
if which gem > /dev/null 2>&1; then
  LOCAL_GEMPATH="`gem environment gempath | cut -d : -f 1`/bin"

  if [ -d "$LOCAL_GEMPATH" ]; then
    PATH="$LOCAL_GEMPATH:$PATH"
  fi
fi

# Add local NixOS into PATH
if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
  . $HOME/.nix-profile/etc/profile.d/nix.sh
fi

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

# Add Node Version Manager into PATH
# https://www.npmjs.com/package/nhttps://www.npmjs.com/package/n
export N_PREFIX="$HOME/.n"
if [ -d "$HOME/.n/bin" ]; then
  PATH="$HOME/.n/bin:$PATH"
fi

# NVM
# https://github.com/nvm-sh/nvm
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

# Rust
if [ -e "$HOME/.cargo/env" ]; then
  . $HOME/.cargo/env
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"

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

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

# CDPATH configuration
# See http://www.caliban.org/bash/#bashtips
#
# The following CDPATH behavior might trigger unexpected behaviors in some
# programs. See example at https://github.com/alecmuffett/eotk/pull/113
# Recommendation is that programs do their own fix (as nothing guarantees
# the CDPATH won't be set).
if [ "$SETCDPATH" != "false" ]; then
  if [ -z "$CDPATH" ]; then
    export CDPATH=".:$HOME:$WORKPATH"
  else
    export CDPATH=".:$HOME:$WORKPATH:$CDPATH"
  fi
fi

# Buil-in "cd" command replacement avoiding echoing the CDPATH
# Based on http://superuser.com/questions/90535/how-do-i-turn-of-auto-echo-in-bash-when-i-cd
# But please note that this workaround will not work for invoked programs (see comment above).
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
}

mknow() {
  suffix="$1"
  folder="`now`"

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

  mkdir $folder && cd $folder
}

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 "$*"
}

mkedit() {
  mktouch "$*"
  $EDITOR "$*"
}

# 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

# Firejail configuration
# This my hide important errors, so it's recommended to try running a
# firejailed command with FIREJAIL_QUIET=no to debug.
export FIREJAIL_QUIET="yes"

# 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

# Set the proper GnuPG TTY when running on console
# See https://stackoverflow.com/questions/51504367/gpg-agent-forwarding-inappropriate-ioctl-for-device#55032706
#     https://superuser.com/questions/1649997/unable-to-decrypt-from-stdin-public-key-decryption-failed-inappropriate-ioctl
if [ -z "$DISPLAY" ]; then
  export GPG_TTY=$(tty)
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 2>&1
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

# Include other profiles
if [ -d "$HOME/.profile.d" ]; then
  for script in `ls $HOME/.profile.d`; do
    source $HOME/.profile.d/$script
  done
fi

# Include custom profiles
if [ -d "$HOME/.custom/profile.d" ]; then
  for script in `ls $HOME/.custom/profile.d`; do
    source $HOME?.custom/profile.d/$script
  done
fi

# Run startup scripts
#if [ -d "$HOME/.custom/rc.d" ]; then
#  run-parts $HOME/.custom/rc.d
#fi

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