chris-marsh / pureline

A Pure Bash Powerline PS1 Command Prompt
MIT License
501 stars 94 forks source link

Add a way to dim specific exit codes #46

Open lynxhug opened 4 years ago

lynxhug commented 4 years ago

I'm using terminal inside Dolphin so there is always 130 exit code in terminal panel when you change directory by clicking it. This commit is adding functionality to change color of return code module for specific exit codes to a different from specified in config file. Basically to grey out Control-C interrupt. With undefined new variables script will operate without changes.

chris-marsh commented 3 years ago

Sorry I've not been very active here over the past while, but eventually coming back to PureLine and the PRs :)

I like the idea of dimming, but I'm thinking it might be simpler to not show 130's?

function return_code_segment {                                                                                                                                                                 
    [[ ${__return_code} -eq 0 || ${__return_code} -eq 130 ]] && return                                                                                                                         

    local bg_color="$1"                                                                                                                                                                        
    local fg_color="$2"                                                                                                                                                                        
    local content rc_symbol                                                                                                                                                                    
    pl_symbol rc_symbol 'return_code'                                                                                                                                                          
    content="${rc_symbol} ${__return_code}"                                                                                                                                                    
    add_segment "$content" "$fg_color" "$bg_color"                                                                                                                                             
    __return_code=0                                                                                                                                                                            
} 
lynxhug commented 3 years ago

Completely hide exit code could be a problem if some other program use it for some reason rather than leaving it for the shell to signal that program was terminated by user. Also for confirmation sake i still want to know that any other programs that i do interrupt with ctrl+c is returning 130 exit code and not 0 for some reason. Probably very low chance for both occurrences but i would still prefer that no exit code on pureline will mean only 0 exit code.