thegogz.github.io

A Salesforce Dev, CoderDojo Champion and Techie

View on GitHub
2 March 2019

Welcome to my blog

by Gogz

|

Ok so I’ve said before I’d do a blog and I never really get around to it. So here we go with another attempt at it.

This started last night when I was researching some interesting things to do with Salesforce DX and more specifically my bash shell.

I came accros this which with a bit of playing around I was able to get working.

Below is what it ended up looking like

custom bash file

Pretty cool huh?

Some things to note.

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""hub: $bldgrn";
  if [ ! $defaultdevhubusername = "null" ]
  then
    echoString=$echoString$defaultdevhubusername"$txtylw (local)"
  else
    echoString=$echoString$globaldefaultdevhubusername"$txtylw (global)"
  fi
  echo "\n"$echoString

  echoString="$bldwht""default: $bldgrn"
  if [ ! $defaultusername = "null" ]
  then
    echoString=$echoString$defaultusername"$txtylw (local)"
  else
    echoString=$echoString$globaldefaultusername"$txtylw (global)"
  fi
  echo $echoString"\n\e[0m"
}

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

PROMPT_COMMAND=print_before_the_prompt
PS1='\w\n$ '

I’m still not quite happy with it but I’ll try to keep her updated with progress.

tags: sfdx - bash - shell - git-bash