[Fish] Better handling of user-defined paths

This commit is contained in:
Lucien Cartier-Tilet 2020-12-10 10:06:46 +01:00
parent 38843d8a4e
commit 54e9e00078
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -181,10 +181,10 @@ Finally, some development packages require the =PKG_CONFIG_PATH= to be set, so l
#+END_SRC #+END_SRC
** ~$PATH~ ** ~$PATH~
Some global variables might sometimes be needed and need to be modified. This is for example the case with my ~PATH~ variable in which I add Rusts Cargos binaries, Gos binaries and my own executables. And of course, dont forget to add the already existing ~PATH~.
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: Global_variables-$PATH-e1320303 :CUSTOM_ID: Global_variables-$PATH-e1320303
:END: :END:
A variable available with the fish shell is ~fish_user_paths~ which lists custom paths to binaries specified by the user. Using this variable ensures they are included in the ~$PATH~ variable only once without the need to set it directly. For instance, my ~PATH~ variable needs Rusts Cargos binaries, Gos binaries, my own executables, and some more.
#+NAME: extra-paths #+NAME: extra-paths
| additional path | what it leads to | | additional path | what it leads to |
@ -199,19 +199,21 @@ Some global variables might sometimes be needed and need to be modified. This is
#+NAME: generate-extra-paths #+NAME: generate-extra-paths
#+BEGIN_SRC emacs-lisp :var paths=extra-paths[,0] :exports none :cache yes #+BEGIN_SRC emacs-lisp :var paths=extra-paths[,0] :exports none :cache yes
(mapconcat (lambda (x) x) (mapconcat (lambda (x) x)
paths " ") paths " \\\n")
#+END_SRC #+END_SRC
#+RESULTS[f1fff053cb9e2239f35571249763683a4a62e643]: generate-extra-paths #+RESULTS[8b780f78d3d321222408ba76c754c920d95b03ac]: generate-extra-paths
: $HOME/.pub-cache/bin $HOME/.local/bin $HOME/go/bin $HOME/.cargo/bin $HOME/.gem/ruby/2.6.0/bin $HOME/.cabal/bin : $HOME/.pub-cache/bin \
: $HOME/.local/bin \
: $HOME/go/bin \
: $HOME/.cargo/bin \
: $HOME/.gem/ruby/2.6.0/bin \
: $HOME/.cabal/bin
The code below ensures the ~PATH~ is updated only at login, and every location is addded only once. So, lets set our user paths:
#+BEGIN_SRC fish :noweb yes #+BEGIN_SRC fish :noweb yes
for p in <<generate-extra-paths()>> set -g fish_user_paths \
if status is-login <<generate-extra-paths()>>
contains $p $PATH || set PATH $p $PATH
end
end
#+END_SRC #+END_SRC
* Abbreviations * Abbreviations