8 ms·
I've added a counter (of successful commands in a row) to my bashrc. I've seen it as high as 120. function promptCommand() { LAST_STATUS=$? # Set t
by kingvash 9y ago
I've added a counter (of successful commands in a row) to my bashrc. I've seen it as high as 120.
function promptCommand()
{
LAST_STATUS=$?
# Set title of window to dir, then add new line to prompt.
PS1='\[\e]0;\w\a\]\n'
if [ $LAST_STATUS -eq 0 ]; then
((successes++))
PS1+='\[\033[1;32m\][$successes]'
else
successes=0
PS1+='\[\033[1;31m\][0 $LAST_STATUS]'
fi
PS1+='\[\033[0;32m\] '
PS1+='\w $(date +%H:%M) \$ \[\033[0m\]'
}
lastStatus=0
successes=-1
PROMPT_COMMAND="promptCommand"
My prompt:
[0] /home/bar/g3 14:19 $ echo "boo"
boo
[1] /home/bar/g3 14:19 $
- kedean 9y agoMan, I hope you don't use grep very often (by default it uses exit code 1 when it doesn't find anything).
- mortehu 9y agoJust pipe the output through cat. By default, the "pipefail" option is not set, so echo foo | grep bar | cat is successful. Of course, this works for any command.
- function_seven 9y agoIf it didn't exist in the first place, then you had no business searching for it. You should have just known not to look. :)
- friendzis 9y agoNegative result is still a result. I sometimes use `grep -r` to check whether "does this set of files contain this particular string?" and "no" is a useful answer :)
- prginthebox 9y agotwas a joke.
- Lio 9y agoI like this joke, it kind of reminds me of the difference between `find_by_id` and `find` in ruby on rails. In the former, if a result can't be found it will return `nil` but in the latter it expects the record to exist and so will raise an exception if it can't be found.
- Shorel 9y agoI've heard that joke once, but in C++
- rusk 9y agoPython: `Dict.get(k)` (`null`) vs `Dict[k]` (`IndexError`)
- philsnow 9y agothat sounds so backwards. `find_by_id` is a lookup, not a search; it seems implied to me that the ID should exist and if it doesn't that's an exception. Whereas `find` is a search and it's not atypical for search results to be empty.
- rapind 9y agoSince I think rails 4 or earlier it's preferred to use `find_by(id: 4)`, but could instead be `find_by(email: "email@example.com")`, or even `find_by(first_name: "Franky', last_name: "Tomato")`. IMO returning nil instead of an exception for the above is practical for me. Much easier to work with. Having `find(4)` raising an exception is because you'll typical use it in your member actions for a controller where it's reasonable to want an exception if something can't be found. It's just Rails being Rails (practical sometimes at the expense of possible interpretation of correctness). You do have to retain stuff like this in your head, but it becomes habit pretty quickly.
- craftyguy 9y agojust add a '|| true' at the end of every call to grep!
- anon335dtzbvc 9y agojust add a '|| true' at the end of every call!
- omginternets 9y ago>grep Not to mention tar which is just impossible to get right on the first try.
- 0xJRS 9y ago>cheat tar
- Yizahi 9y agoEspecially when disarming a nuke
- nobodyorother 9y agoNuke-practice is why I only use tar these days.
- bohinjc 9y agoThis reminds me about https://www.xkcd.com/1168/ https://www.xkcd.com/1168/
- mondoshawan 9y agoIf you're looking for just mistypes, use status 128.