How do I add these directories to my PATH? Whenever I reboot I have to manually add them again

67 Views Asked by At

New to linux terminal, gnome and terminals in general. Thought it would be a good way to learn by customizing UI.

I am trying to automatically add these directories to my PATH instead of doing it manually every time. To be able to run applications installed by DATLinux distro from my terminal in addition to the applications not in the PATHS below.

I have tried to update .profile and .bashrc at the bottom using vim. With the following.

export PATH="/home/oskar/.cari/shims:$PATH"
export PATH="/home/oskar/.cari/bin:$PATH"
export PATH="/home/oskar/.local/bin:$PATH"

OR

export PATH=$PATH:/home/oskar/.cari/shims
export PATH=$PATH:/home/oskar/.cari/bin
export PATH=$PATH:/home/oskar/.local/bin

I am using the Zsh shell

It works if I manually do it everytime.

Is there not a start up script i could write to do so? If i run this would it work: #!/bin/sh export PATH="/home/oskar/.cari/shims:$PATH" export PATH="/home/oskar/.cari/bin:$PATH" export PATH="/home/oskar/.local/bin:$PATH"

Here is code for cari.sh, i see i should add "$0" and run the script?

# For Korn shells (ksh, mksh, etc.), capture $_ (the final parameter passed to
# the last command) straightaway, as it will contain the path to this script.
# For Bash, ${BASH_SOURCE[0]} will be used to obtain this script's path.
# For Zsh and others, $0 (the path to the shell or script) will be used.
_under="$_"
if [ -z "$CARI_DIR" ]; then
  if [ -n "${BASH_SOURCE[0]}" ]; then
    current_script_path="${BASH_SOURCE[0]}"
  elif [[ "$_under" == *".sh" ]]; then
    current_script_path="$_under"
  else
    current_script_path="$0"
  fi

  CARI_DIR="$(dirname "$current_script_path")"
fi
export CARI_DIR
# shellcheck disable=SC2016
[ -d "$CARI_DIR" ] || printf '$CARI_DIR is not a directory'

# Add cari to PATH
#
# if in $PATH, remove, regardless of if it is in the right place (at the front) or not.
# replace all occurrences - ${parameter//pattern/string}
CARI_BIN="${CARI_DIR}/bin"
CARI_USER_SHIMS="${CARI_DATA_DIR:-$HOME/.cari}/shims"
[[ ":$PATH:" == *":${CARI_BIN}:"* ]] && PATH="${PATH//$CARI_BIN:/}"
[[ ":$PATH:" == *":${CARI_USER_SHIMS}:"* ]] && PATH="${PATH//$CARI_USER_SHIMS:/}"
# add to front of $PATH
PATH="${CARI_BIN}:$PATH"
PATH="${CARI_USER_SHIMS}:$PATH"

# shellcheck source=lib/cari.sh
# Load the cari wrapper function
. "${CARI_DIR}/lib/cari.sh"
. "${CARI_DIR}/completions/cari.bash"

unset _under current_script_path CARI_BIN CARI_USER_SHIMS
#!/usr/bin/env bash

# shellcheck source=lib/utils.bash
. "$(dirname "$(dirname "$0")")/lib/utils.bash"

find_cmd() {
  local cmd_dir="$1"
  shift

  local cmd_name
  local args_offset="$#"
  cmd_name="command-$(tr ' ' '-' <<<"${@:1:${args_offset}}").bash"
  while [ ! -f "$cmd_dir/$cmd_name" ] && [ "$args_offset" -gt 0 ]; do
    args_offset=$((args_offset - 1))
    cmd_name="command-$(tr ' ' '-' <<<"${@:1:${args_offset}}").bash"
  done

  if [ -f "$cmd_dir/$cmd_name" ]; then
    printf "%s %s\\n" "$cmd_dir/$cmd_name" "$((args_offset + 1))"
  elif [ -f "$cmd_dir/command.bash" ]; then
    printf "%s %s\\n" "$cmd_dir/command.bash" 1
  fi
}

find_cari_cmd() {
  local cari_cmd_dir
  cari_cmd_dir="$(cari_dir)/lib/commands"
  case "$1" in
    'add'                   | \
    'current'               | \
    'env'                   | \
    'exec'                  | \
    'export-shell-version'  | \
    'global'                | \
    'install'               | \
    'info'                  | \
    'install'               | \
    'latest'                | \
    'list'                  | \
    'list-all'              | \
    'plugin-push'           | \
    'plugins'               | \
    'remove'                | \
    'reshim'                | \
    'shim-versions'         | \
    'uninstall'             | \
    'update'                | \
    'upgrade'               | \
    'which' )
      printf "%s %s\\n" "$cari_cmd_dir/command-$1.bash" 2
    ;;
    '' | '--help' | '-h')
      printf "%s %s\\n" "$cari_cmd_dir/command-help.bash" 2
    ;;
    '--version')
      printf "%s %s\\n" "$cari_cmd_dir/command-version.bash" 2
    ;;
    *)
      find_cmd "$cari_cmd_dir" "$@"
    ;;
  esac
}

find_plugin_cmd() {
  local CARI_CMD_FILE args_offset
  if [ -d "$(get_plugin_path "$1")/bin" ]; then
    IFS=' ' read -r CARI_CMD_FILE args_offset <<<"$(find_cmd "$(get_plugin_path "$1")/lib/commands" "${@:2}")"
    if [ -n "$CARI_CMD_FILE" ]; then
      args_offset=$((args_offset + 1)) # since the first argument is the plugin name
      printf "%s %s\\n" "$CARI_CMD_FILE" "$args_offset"
    fi
  fi
}

cari_cmd() {

  local CARI_CMD_FILE args_offset

  if [ "shell" == "$1" ]; then
    printf "Shell integration is not enabled. Please ensure you source cari in your shell setup." >&2
    exit 1
  fi

  IFS=' ' read -r CARI_CMD_FILE args_offset <<<"$(find_cari_cmd "$@")"
  if [ -z "$CARI_CMD_FILE" ]; then
    IFS=' ' read -r CARI_CMD_FILE args_offset <<<"$(find_plugin_cmd "$@")"
  fi

  if [ -x "$CARI_CMD_FILE" ]; then
    exec "$CARI_CMD_FILE" "${@:${args_offset}}"
  elif [ -f "$CARI_CMD_FILE" ]; then
    set -- "${@:${args_offset}}"
    . "$CARI_CMD_FILE"
  else
    local cari_cmd_dir
    cari_cmd_dir="$(cari_dir)/lib/commands"
    printf "%s\\n" "Unknown command: \`cari ${*}\`" >&2
    return 127
  fi

}

#cari_cmd "$@"

Extract from bash.rc

which_term=`ps -o 'cmd=' -p $(ps -o 'ppid=' -p $$)`
if [[ $which_term != *"gnome-terminal"* ]] && [[ $which_term != *"datlinux"* ]]; then
   neofetch
fi

.profile

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

if [ -d $HOME/.cari ]; then
    export CARI_DIR=$HOME/.cari
    export CARI_VENV_PATH=$HOME/.cari/venv
    export CARI_PIP_CACHE=$HOME/.pip-cache
    . $HOME/.cari/cari.sh
fi

1

There are 1 best solutions below

1
svlasov On

I have tried to update .profile and .bashrc at the bottom

This is ok for for bash but not for zsh. Zsh does not read .bashrc or .profile (unless run in sh or ksh compatibility mode). Instead you should use .zshenv.

If you want to keep using .profile (if you choose so, you should maintain it compatible for bash and zsh) then create ~/.zshenv:

. $HOME/.profile

or otherwise export your PATH variable directly in .zshenv.