Skip to content

Commit

Permalink
Merge pull request #3 from mschmidtkorth/develop
Browse files Browse the repository at this point in the history
 Add only generate glyphs if in SFDX directory
  • Loading branch information
mschmidtkorth authored Feb 21, 2020
2 parents de9903c + 3244bf1 commit 4213cf8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Adds the status of Salesforce DX projects to your fish prompt. Compatible with o
- If you are using [Pure](https://github.com/rafaelrinaldi/pure) prompt: Copy `fish_prompt.fish_pure` to `~/.config/fish/functions/` and rename to `fish_prompt.fish` (replace existing file, backup before)
- If you are using [bobthefish](https://github.com/oh-my-fish/theme-bobthefish) prompt: Copy `fish_prompt.fish_bobthefish` to `~/.config/fish/functions/` and rename to `fish_prompt.fish` (replace existing file, backup before)
- If you are using any other prompt or the default fish prompt: Put `echo -e -n (_prompt_sfdx)` wherever you would like to see the output in `~/.config/fish/functions/fish_prompt.fish`
- If you are using [Nerd Fonts](https://github.com/ryanoasis/nerd-fonts), set `set -g nerdFonts no` to `set -g nerdFonts yes` in `_prompt_sfdx.fish` (recommended e.g. for bobthefish)

**Note** You may also modify `fish_prompt.fish` instead of replacing it.

Expand Down
25 changes: 10 additions & 15 deletions _prompt_sfdx.fish
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
function _prompt_sfdx \
-d 'Print sfdx scratch information: Default alias and username, expiration date of default alias/username\'s org'

set -g configDir (_prompt_sfdx_configDir)
_prompt_sfdx_configDir

if test -e $configDir/sfdx-project.json # Is current dir a SFDX project (sub)directory?
#------- Create global variables
set -g nerdFonts no
set -g nerdFonts yes # For bobthefish/Pure prompt: yes
set -g aliasOrUsername (_prompt_sfdx_aliasOrUsername)
set -g usernameForAlias (_prompt_sfdx_usernameForAlias)

Expand All @@ -28,13 +28,17 @@ function _prompt_sfdx \
# end

#------- Generate prompt output
if test $nerdFonts = yes # TODO: Implement arrow segmentation using unicode glyphs
set sfdx_prompt (set_color 489cdc)$right_arrow_glyph (set_color white -b 489cdc) \uf01a $sfdx_prompt_aliasOrUsername $sfdx_prompt_username (set_color 489cdc)$right_black_arrow_glyph #$sfdx_prompt_expiration
if test $nerdFonts = yes
# set sfdx_prompt (set_color 489cdc)$right_arrow_glyph (set_color white -b 489cdc) \uf01a $sfdx_prompt_aliasOrUsername $sfdx_prompt_username (set_color 489cdc)$right_black_arrow_glyph # For Pure prompt with MesloLGS NF
set sfdx_prompt (set_color white -b 489cdc) \uf0c2 $sfdx_prompt_aliasOrUsername $sfdx_prompt_username # For bobthefish prompt with Hack Nerd Font
else
set sfdx_prompt (set_color white -b 489cdc) \u2601 $sfdx_prompt_aliasOrUsername$sfdx_prompt_username #$sfdx_prompt_expiration
# TODO: MesloLGS NF (Nerd Font) makes the unicode characters appear tiny (eg Cloud)
end
echo " " $sfdx_prompt" "
if test $nerdFonts = no # not used with bobthefish
echo " " $sfdx_prompt" " # For Pure prompt
else
echo -en $sfdx_prompt # For bobthefish prompt
end
end
end

Expand Down Expand Up @@ -72,13 +76,4 @@ function _prompt_sfdx_orgExpiration \
else
echo false
end
end

function _prompt_sfdx_configDir \
-d 'Get root project folder of current project.'
if string match -q -r 'force-app' $PWD # If $PWD contains force-app, we are in a subdirectory
echo (string replace -r 'force-app.*' '' -- $PWD)
else
echo $PWD
end
end
10 changes: 10 additions & 0 deletions _prompt_sfdx_configDir.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function _prompt_sfdx_configDir \
-d 'Get root project folder of current project.'
if string match -q -r 'force-app' $PWD # If $PWD contains force-app, we are in a subdirectory
set -g configDir (string replace -r 'force-app.*' '' -- $PWD)
# echo (string replace -r 'force-app.*' '' -- $PWD)
else
set -g configDir $PWD
# echo $PWD
end
end
9 changes: 6 additions & 3 deletions fish_prompt.fish_bobthefishPrompt
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,11 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome'
__bobthefish_prompt_dir $real_pwd
end

# MSK Add prompt_sfdx
__bobthefish_start_segment 489cdc
echo -e -n (_prompt_sfdx)
# MSK Add prompt_sfdx
_prompt_sfdx_configDir
if test -e $configDir/sfdx-project.json
__bobthefish_start_segment 489cdc
echo -e -n (_prompt_sfdx)
end
__bobthefish_finish_segments
end

0 comments on commit 4213cf8

Please sign in to comment.