caiogondim / bullet-train.zsh

:bullettrain_side: An oh-my-zsh shell theme based on the Powerline Vim plugin
MIT License
2.82k stars 383 forks source link

Suspend return value: 148 #177

Open MedicineYeh opened 7 years ago

MedicineYeh commented 7 years ago

Hi, I love this theme a lot, but there's a small flaw when I suspend process which is the return value would be 148 with "BULLETTRAIN_STATUS_ERROR_BG" color. I suggest adding a value detection in prompt_status() function. According to this thread and ABI, the value bigger than 128 is exit code 128 + signal SIGTSTP. Since the value has its meaning and text, we could show the text on the prompt instead of showing the return value. For example, the value 148 should be "TSTP". The text of return condition could be easily retrieved by using kill -l $?.

dawikur commented 7 years ago

Ohh, very good idea!

caiogondim commented 7 years ago

Ow I was not aware of it Bash and all it's hidden magic constants...

So, if exit_code > 128 we can check it's value with kill -l $??

MedicineYeh commented 7 years ago

Yes, you can simply try it out by opening a vim editor and then ctrl+z putting it to the background. After that, enter kill -l $?. You will see a different message. Magic~ :P However, it might not be a good idea for values less than 128, since it would also use the signal number (SIGTSTP) to interpret the value, ex: a return value of 9 would be "KILL", which is not correct.

On more thing, don't use kill -l $? in prompt_status(), because the return value has been changed in build_prompt(). Instead, you would want to use kill -l $(($RETVAL - 128)), which simply reuse the variable you have.

caiogondim commented 7 years ago

Could you make a PR? You know lots more than me on this regard =)

dbkaplun commented 7 years ago

This functionality seems very interesting but the numeric exit code is most useful to me. Can we put this feature behind a flag, or have both the number and name output at once?

MedicineYeh commented 7 years ago

I ended up with the optional feature way. Please take a look at the PR #179. Now, the signal would be interpreted to a meaningful name. EX:

14:48:39  ✘ SEGV   ~ 
14:57:13  ✘ TSTP  ⚙  ~
15:01:19  ✘ KILL   ~
MedicineYeh commented 7 years ago

By the way, in my own version, I specifically filter out the return value of 148, which is "suspend" (ctrl;+z). It's just because I do this so often and I want my screen to be clean when there is nothing bad happen. This is just my habit, so I didn't put it in the PR. You can consider whether to put the following line in.

if [[ -n "$symbols" && $RETVAL -eq 148 ]]; then
  prompt_segment $BULLETTRAIN_STATUS_BG $BULLETTRAIN_STATUS_FG "⚙"
elif [[ -n "$symbols" && $RETVAL -ne 0 ]]; then
  ...