.profile 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #!/bin/sh
  2. ## This file should be automatically sourced by the login manager or Bash if
  3. ## .bash_profile does not exist. If this file is not automatically sourced,
  4. ## do it from the shell config to me sure it applies to TTY as well.
  5. ## Mask
  6. ## Result for 027 is "rwxr-x---". 022 is the popular default.
  7. ##
  8. ## As a result applications make the bad assumption # that "others" have access.
  9. ## Another drawback of 027 is that is behaves badly with default sudo config: for
  10. ## instance "sudo mkdir foo" will effectively create a "foo" folder whose owner
  11. ## is root and with permission 027, even if root's umask is 022. This is
  12. ## usually very bad.
  13. ## See https://wiki.archlinux.org/index.php/Sudo#Permissive_umask.
  14. ##
  15. ## It is possible to override sudo's umask by adding the following to the
  16. ## sudoers file:
  17. ##
  18. ## Defaults umask = 0022
  19. ## Defaults umask_override
  20. # umask 027
  21. ## Preliminary path definitions. For security reasons (and bad programming
  22. ## assumptions) you should always append entries to PATH, not prepend them.
  23. appendpath () {
  24. [ $# -eq 2 ] && PATHVAR=$2 || PATHVAR=PATH
  25. [ -d "$1" ] || return
  26. eval echo \$$PATHVAR | grep -q "\(:\|^\)$1\(:\|$\)" && return
  27. eval export $PATHVAR="\$$PATHVAR:$1"
  28. }
  29. prependpath () {
  30. [ $# -eq 2 ] && PATHVAR=$2 || PATHVAR=PATH
  31. [ -d "$1" ] || return
  32. eval echo \$$PATHVAR | grep -q "\(:\|^\)$1\(:\|$\)" && return
  33. eval export $PATHVAR="$1:\$$PATHVAR"
  34. }
  35. ## Use this to override system executables.
  36. prependpath "${HOME}/personal/hackpool"
  37. ## TeXlive -- TODO: Remove once guix has packaged it all properly.
  38. TEXDIR="${TEXDIR:-/usr/local/texlive}"
  39. if [ -d "${TEXDIR}" ]; then
  40. TEXYEAR=$(/bin/ls -1r "${TEXDIR}" | grep -m1 "[0-9]\{4\}")
  41. TEXDISTRO=$(uname -m)-$(uname | awk '{print tolower($0)}')
  42. TEXFOLDER="${TEXDIR}/${TEXYEAR}/bin/${TEXDISTRO}"
  43. if [ -d "${TEXFOLDER}" ]; then
  44. appendpath $TEXFOLDER
  45. ## Same for INFOPATH, which should have an empty entry
  46. ## at the end, otherwise Emacs will not use standard locations.
  47. prependpath ${TEXDIR}/${TEXYEAR}/texmf/doc/info INFOPATH
  48. if [ "$(uname -o)" = "GNU/Linux" ]; then
  49. ## Under GNU/Linux, MANPATH must contain one empty entry for 'man' to
  50. ## lookup the default database. Since BSD uses 'manpath' utility, the
  51. ## MANPATH variable is not needed.
  52. prependpath ${TEXDIR}/${TEXYEAR}/texmf/doc/man MANPATH
  53. fi
  54. fi
  55. unset TEXYEAR
  56. unset TEXDISTRO
  57. unset TEXFOLDER
  58. fi
  59. unset TEXDIR
  60. export BIBINPUTS=~/personal/bibliography
  61. ## Go
  62. if [ -d "$HOME/go" ]; then
  63. export GOPATH=~/go:~/.go-tools
  64. appendpath "$HOME/.go-tools/bin"
  65. appendpath "$HOME/go/bin"
  66. command -v godoc >/dev/null 2>&1 && godoc -http :6060 -play 2>/dev/null &
  67. fi
  68. ## Cask
  69. appendpath "$HOME/.cask/bin"
  70. ## Last PATH entries.
  71. appendpath "/usr/lib/surfraw"
  72. appendpath "${HOME}/personal/games/launchers"
  73. appendpath "${HOME}/.local/bin"
  74. command -v pacman >/dev/null 2>&1 && appendpath "${HOME}/.local/bin/pacman"
  75. ## mcron: needs to be run after PATH is fully set or else local programs could
  76. ## be missing.
  77. if command -v mcron >/dev/null 2>&1; then
  78. mcron &
  79. fi
  80. ## Remove less history.
  81. LESSHISTFILE='-'
  82. ## Manpage.
  83. export MANPAGER="less -s"
  84. export MANWIDTH=80
  85. ## Time display (with ls command for example). GNU 'ls' only.
  86. export TIME_STYLE=+"|%Y-%m-%d %H:%M:%S|"
  87. ## SSH-Agent
  88. ## Set SSH to use gpg-agent
  89. unset SSH_AGENT_PID
  90. if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
  91. export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
  92. fi
  93. # Set GPG TTY
  94. export GPG_TTY=$(tty)
  95. # Refresh gpg-agent tty in case user switches into an X session
  96. gpg-connect-agent updatestartuptty /bye >/dev/null
  97. ## Linux specific
  98. if [ "$(uname -o)" = "GNU/Linux" ] ; then
  99. ## Startup error log.
  100. ## dmesg
  101. log_dmesg="$(dmesg | grep -i error)"
  102. [ -n "$log_dmesg" ] && echo "$log_dmesg" > "$HOME/errors-dmesg.log" || rm "$HOME/errors-dmesg.log" 2>/dev/null
  103. ## systemd
  104. if command -v systemctl >/dev/null 2>&1; then
  105. count="$(systemctl show | awk -F= '$1=="NFailedUnits" {print $2; exit}')"
  106. if [ $count -ne 0 ]; then
  107. systemctl -l --failed > "$HOME/errors-systemd.log"
  108. else
  109. rm -f "$HOME/errors-systemd.log"
  110. fi
  111. fi
  112. ## Set sound volume. (Useless when running Pulseaudio.)
  113. # amixer 2>/dev/null | grep -q PCM && amixer set PCM 100%
  114. ## External device auto-mounting.
  115. ## If already started, the new process will replace the old one.
  116. if command -v udiskie >/dev/null 2>&1; then
  117. udiskie &
  118. elif command -v devmon >/dev/null 2>&1; then
  119. devmon &
  120. else
  121. udisks-automount &
  122. fi
  123. fi
  124. ## Wine DLL overrides.
  125. ## Remove the annoying messages for Mono and Gecko.
  126. export WINEDLLOVERRIDES="mscoree,mshtml="
  127. ## Do not create desktop links or start menu entries.
  128. export WINEDLLOVERRIDES="$WINEDLLOVERRIDES;winemenubuilder.exe=d"
  129. ## Pacman asp root.
  130. if command -v asp >/dev/null 2>&1; then
  131. export ASPROOT="$HOME/.cache/asp"
  132. fi
  133. ## Guix
  134. if command -v guix >/dev/null 2>&1; then
  135. export GUIX_PACKAGE_PATH="$HOME/.guix-packages"
  136. fi
  137. ## Default text editor
  138. ## 'em' is a custom wrapper for emacsclient. See '.bin/em'.
  139. ## VISUAL is given priority by some programs like Mutt. This way we can separate
  140. ## editors that wait from those that don't.
  141. for i in emacsclient em emacs vim vi nano; do
  142. command -v $i >/dev/null 2>&1 && export EDITOR=$i && break
  143. done
  144. GIT_EDITOR="$EDITOR"
  145. VISUAL="$EDITOR"
  146. [ "$GIT_EDITOR" = em ] && GIT_EDITOR=emc
  147. [ "$VISUAL" = em ] && VISUAL=emw
  148. export GIT_EDITOR
  149. export VISUAL
  150. ## $HOME software install
  151. ## See http://nullprogram.com/blog/2017/06/19/.
  152. ## The variables should not contain paths to non-existing folders as it may
  153. ## break compilers.
  154. prependpath "$HOME/.local/include" C_INCLUDE_PATH
  155. prependpath "$HOME/.local/include" CPLUS_INCLUDE_PATH
  156. prependpath "$HOME/.local/lib" LIBRARY_PATH
  157. prependpath "$HOME/.local/lib/pkgconfig" PKG_CONFIG_PATH
  158. prependpath "$HOME/.local/share/info" INFOPATH
  159. prependpath "$HOME/.local/share/man" MANPATH
  160. ## If you install a library in your home directory that is also installed on the
  161. ## system, and then run a system program, it may be linked against your library
  162. ## rather than the library installed on the system as was originally
  163. ## intended. This could have detrimental effects.
  164. # export LD_LIBRARY_PATH=$HOME/.local/lib
  165. ## Hook. Should be sourced last
  166. [ -f ~/.profile_hook ] && . ~/.profile_hook
  167. ## Hook example
  168. #
  169. # export CPPFLAGS=-I$HOME/local/usr/include
  170. # export LDFLAGS=-L$HOME/local/usr/lib
  171. #
  172. # appendpath "$HOME/local/usr/lib/python2.7/dist-packages/" PYTHONPATH
  173. # export LUA_CPATH="$HOME/local/usr/lib/lib?.so;$(lua -e "print(package.cpath)")"
  174. #
  175. # umask 077
  176. ## End: Source .bashrc. The rc file should guard against non-interactive shells.
  177. [ "$(ps -o comm= $$)" != bash ] && return
  178. [ -f ~/.bashrc ] && . ~/.bashrc
  179. [ -z "$DISPLAY" ] && [ "$(tty)" = '/dev/tty1' ] && exec xinit -- vt01