thegogz.github.io

A Salesforce Dev, CoderDojo Champion and Techie

View on GitHub
2 March 2019

Updated SFDX Aware Bash Profile

by Gogz

|

I knew there was something missing from the last version. So here’s the latest

Ends up looking like this

Updated Bash Shell

And the updated .bash_profile

bldwht='\e[1;37m' # White
bldgrn='\e[1;32m' # Green
txtylw='\e[0;33m' # Yellow

get_usernames() {
  config="$(cat .sfdx/sfdx-config.json 2> /dev/null)";
  globalConfig="$(cat ~/.sfdx/sfdx-config.json)";

  defaultusername="$(echo ${config} | jq -r .defaultusername)"
  defaultdevhubusername="$(echo ${config} | jq -r .defaultdevhubusername)"
  globaldefaultusername="$(echo ${globalConfig} | jq -r .defaultusername)"
  globaldefaultdevhubusername="$(echo ${globalConfig} | jq -r .defaultdevhubusername)"

  echoString="$bldwht""Devhub: $bldgrn";
  if [ ! $defaultdevhubusername = "null" ]
  then
    echoString=$echoString$defaultdevhubusername"$txtylw (local)"
  else
    echoString=$echoString$globaldefaultdevhubusername"$txtylw (global)"
  fi
  echo "\n"$echoString

  echoString="$bldwht""Default Scratch Org: $bldgrn"
  if [ ! $defaultusername = "null" ]
  then
    echoString=$echoString$defaultusername"$txtylw (local)"
  elif [ "$globaldefaultusername" = "null" ]
  then
    echoString=""
  else
    echoString=$echoString$globaldefaultusername"$txtylw (global)"
  fi
  echo $echoString
}

print_before_the_prompt () {
    printf "$(get_usernames)"
}

PROMPT_COMMAND=print_before_the_prompt
PS1='\n\[\033[1;33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ '

tags: sfdx - bash - shell - git-bash - salesforce - git