Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue when the # of jobs is greater than 1 #445

Merged
merged 5 commits into from
Jul 20, 2018
Merged

fix issue when the # of jobs is greater than 1 #445

merged 5 commits into from
Jul 20, 2018

Conversation

guilhermeleobas
Copy link
Contributor

Description

This PR fixes #444

Screenshot

image


[[ $jobs_amount -gt 0 ]] || return
[[ $jobs_amount -eq 1 ]] && jobs_amount=''

if [[ $jobs_amount -gt 1 ]]; then
jobs_amount=" ${jobs_amount}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my symbol it looks better without a space, maybe instead of doing this append a space to SPACESHIP_JOBS_SYMBOL in your config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the output of jobs without appending a space. Seems odd to me.

image

What do you think? Should I keep the space or remove it?

Copy link
Contributor

@maximbaz maximbaz May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it optional, have or not space before the job count. Maybe call it SPACESHIP_JOBS_AMOUNT_PREFIX and set it to empty string by default, not to change behavior for existing users. Maybe create SPACESHIP_JOBS_AMOUNT_SUFFIX as well, not to return to this matter in future again 🙂

Here's how it looks for me:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! This last commit also fixes #272

@@ -20,14 +21,14 @@ SPACESHIP_JOBS_COLOR="${SPACESHIP_JOBS_COLOR="blue"}"
spaceship_jobs() {
[[ $SPACESHIP_JOBS_SHOW == false ]] && return

local jobs_amount=$( (jobs) | wc -l )
local jobs_amount=$( jobs -d | awk '!/pwd/' | wc -l | tr -d " ")

[[ $jobs_amount -gt 0 ]] || return
[[ $jobs_amount -eq 1 ]] && jobs_amount=''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'd want to empty the SPACESHIP_JOBS_SPACE_PREFIX when jobs amount is 1, wouldn't you?

Because if not, instead of creating this new variable you could have as well just configured
SPACESHIP_JOBS_SYMBOL="✦ " (with an extra space in the end, which is a common practice in spaceship)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name it SPACESHIP_JOBS_AMOUNT_PREFIX then, to indicate that it has effect only when amount is visible? And also maybe add SPACESHIP_JOBS_AMOUNT_SUFFIX, just for consistency and completeness 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done!

@@ -11,6 +11,8 @@ SPACESHIP_JOBS_PREFIX="${SPACESHIP_JOBS_PREFIX=""}"
SPACESHIP_JOBS_SUFFIX="${SPACESHIP_JOBS_SUFFIX=" "}"
SPACESHIP_JOBS_SYMBOL="${SPACESHIP_JOBS_SYMBOL="✦"}"
SPACESHIP_JOBS_COLOR="${SPACESHIP_JOBS_COLOR="blue"}"
SPACESHIP_JOBS_AMOUNT_PREFIX="${SPACESHIP_JOBS_AMOUNT_PREFIX=" "}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please keep the current behavior and have empty default prefix 😛

if [[ $jobs_amount -eq 1 ]]; then
jobs_amount='' ;
SPACESHIP_JOBS_AMOUNT_PREFIX='' ;
SPACESHIP_JOBS_AMOUNT_SUFFIX='' ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need semicolons

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done!

@guilhermeleobas
Copy link
Contributor Author

Hi @maximbaz, is there anything else you would like me to add/modify?

@maximbaz
Copy link
Contributor

No, I think it's perfect. I wish your PR was merged long time ago, but I don't have the blessing to do so myself — it's the prerogative of @denysdovhan or @salmanulfarzy.

@@ -11,6 +11,8 @@ SPACESHIP_JOBS_PREFIX="${SPACESHIP_JOBS_PREFIX=""}"
SPACESHIP_JOBS_SUFFIX="${SPACESHIP_JOBS_SUFFIX=" "}"
SPACESHIP_JOBS_SYMBOL="${SPACESHIP_JOBS_SYMBOL="✦"}"
SPACESHIP_JOBS_COLOR="${SPACESHIP_JOBS_COLOR="blue"}"
SPACESHIP_JOBS_AMOUNT_PREFIX="${SPACESHIP_JOBS_AMOUNT_PREFIX=""}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only value that I can think for this variable is space and find no need for SPACESHIP_JOBS_AMOUNT_SUFFIX. Why not just make it SPACESHIP_JOBS_SYMBOL="✦ " as suggested by @maximbaz.

This patch also have the same effect right ?
diff --git a/sections/jobs.zsh b/sections/jobs.zsh
index 3f24470..d41cf77 100644
--- a/sections/jobs.zsh
+++ b/sections/jobs.zsh
@@ -9,10 +9,8 @@
 SPACESHIP_JOBS_SHOW="${SPACESHIP_JOBS_SHOW=true}"
 SPACESHIP_JOBS_PREFIX="${SPACESHIP_JOBS_PREFIX=""}"
 SPACESHIP_JOBS_SUFFIX="${SPACESHIP_JOBS_SUFFIX=" "}"
-SPACESHIP_JOBS_SYMBOL="${SPACESHIP_JOBS_SYMBOL="✦"}"
+SPACESHIP_JOBS_SYMBOL="${SPACESHIP_JOBS_SYMBOL="✦ "}"
 SPACESHIP_JOBS_COLOR="${SPACESHIP_JOBS_COLOR="blue"}"
-SPACESHIP_JOBS_AMOUNT_PREFIX="${SPACESHIP_JOBS_AMOUNT_PREFIX=""}"
-SPACESHIP_JOBS_AMOUNT_SUFFIX="${SPACESHIP_JOBS_AMOUNT_SUFFIX=""}"
 
 # ------------------------------------------------------------------------------
 # Section
@@ -28,13 +26,12 @@ spaceship_jobs() {
 
   if [[ $jobs_amount -eq 1 ]]; then
     jobs_amount=''
-    SPACESHIP_JOBS_AMOUNT_PREFIX=''
-    SPACESHIP_JOBS_AMOUNT_SUFFIX=''
+    SPACESHIP_JOBS_SYMBOL="✦"
   fi
 
   spaceship::section \
     "$SPACESHIP_JOBS_COLOR" \
     "$SPACESHIP_JOBS_PREFIX" \
-    "${SPACESHIP_JOBS_SYMBOL}${SPACESHIP_JOBS_AMOUNT_PREFIX}${jobs_amount}${SPACESHIP_JOBS_AMOUNT_SUFFIX}" \
+    "${SPACESHIP_JOBS_SYMBOL}${jobs_amount}" \
     "$SPACESHIP_JOBS_SUFFIX"
 }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly @salmanulfarzy, with your proposal you are hardcoding the jobs symbol and not allowing user to override it.

if [[ $jobs_amount -eq 1 ]]; then
     jobs_amount=''
    SPACESHIP_JOBS_SYMBOL="✦"
fi

@salmanulfarzy salmanulfarzy added the bug Bug related to code base, behavior, displaying, etc. label Jul 20, 2018
Copy link
Member

@salmanulfarzy salmanulfarzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse us for the delay @guilhermeleobas

@salmanulfarzy salmanulfarzy merged commit 40f5226 into spaceship-prompt:master Jul 20, 2018
@guilhermeleobas
Copy link
Contributor Author

No problem, thanks for the review!

@tomislav
Copy link

This commit seems to have broken jobs on macOS. See #498

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug related to code base, behavior, displaying, etc.
Development

Successfully merging this pull request may close these issues.

Trailing spaces when the number of background jobs is greater than 1
4 participants