7 ms·
Shell Gamification (how I learn to use my shell aliases)
- deleted 14y ago[deleted]
- jerf 14y agoIf you want to make it so that any changes stick, you have to make it so the old way doesn't work anymore. I remapped my Caps Lock to several things over the years, but it isn't until I learned to unmap the original key that any of them stuck. If you turn out not to like it, switch back. It's a bit of a challenge to wrap something like 'git' with a shell script that spanks you for doing the wrong thing, but that's a good shell learning exercise. A point scheme is still too diffuse and the feedback still too slow vs. It Didn't Work occurring instantly. You'd be amazed at how quickly you learn new keystrokes this way.
- dbaupp 14y agoIt's not so much of a challenge, git-achievements does it in a few lines of bash: https://github.com/icefox/git-achievements/blob/gh-pages/git-achievements#L487 https://github.com/icefox/git-achievements/blob/gh-pages/git... (The interesting logic happens elsewhere, but the above template demonstrates that one can wrap git without too much trouble and without reducing functionality.)
- columbo 14y agoHere's another hackish way to do this, probably a bad idea, insert in your profile git() { if [[ $@ == "status" ]]; then echo "NOT TODAY BUB (hint, use gs)"; else command git "$@"; fi; } alias gs='git status -' edit: removed ' | more'
- dbaupp 14y agoWhy the piping into more?
- columbo 14y agoHah, that would be because I copied the line from a blog/example somewhere and just replaced a few of the words without really looking at the script.
- hackmiester 14y agoI don't know. I thought it was because if you pipe into "less," it will wait for you to hit 'q' until letting you carry on entering commands. But "more" does not have this behavior.
- xyzzyb 14y agoPassing -F to less causes it to automatically quit if the file can be displayed on one screen.
- naner 14y agoI sort of did the opposite. I took all my aliases that were created because I couldn't remember something (commandline switches, non-trivial tool invocations, non-trivial regexes, etc.) and just set the alias to echo the command. Whenever I'd attempt to use the alias, it would just print and I'd have to retype it by hand. Eventually I learned everything I used to have trouble remembering and have became much more fluent with command line utilities and bash. I still leave convenience aliases intact. Nobody needs to be typing --color=auto every time they ls.
- derleth 14y ago> I still leave convenience aliases intact. Nobody needs to be typing --color=auto every time they ls. Hm. All of my aliases are convenience aliases: cls=clear # Yes, I started out in DOS ls=ls --color=auto ll=ls -l ll.=ls -al And that's it. It's amazing how different peoples' workflows become once a tool allows a certain level of customizability.
- vhost- 14y ago> cls=clear # Yes, I started out in DOS ctlr + l is your new best friend.
- markdrago 14y agoawesome quote from article: "Why do something reasonable when you have the opportunity to do something ridiculous?" ... explains so much code ...
- irollboozers 14y agoThat for me also summed up nicely what separates a coder from a hacker. :]
- jayferd 14y agoFor aliases, convenience functions, and fancy widgets, my philosophy is one word: wait. I make myself go through the trouble of doing it the usual way for a little while. This way, I usually end up with much more domain knowledge and a much more elegant solution than if I'd rushed in to make things easier right of the bat. For example, I don't have `alias gs='git status'`. Just `alias g=git` works great, and git has its own awesome alias system with tab completion that gets me the rest of it. So instead of `gs` I type `g s`, and I get tab completion on all the flags.
- robert-boehnke 14y agoTab completion and aliases need not be mutually exclusive. For instance, in zsh you can use: alias gs='git status' compdef _git gs=git-status FYI: I also mapped g without parameters to `git status -sb` but g with parameters will simply execute everything as normal g () { if [ $# -eq 0 ] then git status -sb else git $* fi } compdef g=git
- jayferd 14y agoNeat! I'll try that using the g() function. I would replace your $* with "$@" (in double quotes), though, so it doesn't try to re-split your arguments by the IFS. (Yes, $@ is a gigantic hack, but a necessary one.) See http://stackoverflow.com/questions/3008695/what-the-difference-between-and-in-bash#3008734 http://stackoverflow.com/questions/3008695/what-the-differen...
- LukeShu 14y agoIt only looks like a hack until you understand Bash arrays.
- pydave 14y agoI was about to ask how you got your alias working with completion, and then I found this: http://stackoverflow.com/questions/342969/how-do-i-get-bash-completion-to-work-with-aliases http://stackoverflow.com/questions/342969/how-do-i-get-bash-... I've never messed with bash completion before, but it was as simple as adding this to my bash_aliases: complete -o default -o nospace -F _git g
- Dru89 14y agoI love this. I'll try implementing it in my shell later this week. I've been looking for a great way to remember all of my custom aliases.
- pserwylo 14y agoThis is cool. I am thinking of gamifying my alarm clock in the morning, so that I earn more XP by not snoozing, and just waking up. Primarily it is a way to help give my mate some experience programming, but I also hope that it will help kick my morning alarm snoozing habit. In the future, I thought it would be cool if you could just pass it new config files to allow gamifying everything. For example, if you want to kick your fast-food-for-lunch-habit, then allow the gamify-everything app to award XP and trophies for things such as "Making your own lunch for X straight days"
- mdonahoe 14y agoBy far my biggest timesaver aliases are for cd-ing to commonly used directories. alias ch="ch ~/Repositories/my_project/foo" alias cn="cd ~/Repositories/my_other_project"
- mmozuras 14y agoInstead of creating aliases, I'm using z (https://github.com/rupa/z https://github.com/rupa/z) for that. You use it instead of cd to navigate to the most frequently used directories anywhere.
- mdonahoe 14y agoThanks for the tip. I'll try it out. However, I am wary of "smart" things that change with usage. I like my tools to be consistent and predicable. For example, I am constantly getting burned by alt-tab That said, I imagine the "frecency" component of z makes it more reliable.
- pydave 14y ago[bashmarks](https://github.com/huyng/bashmarks https://github.com/huyng/bashmarks) does something similar: it provides a command to set a named bookmark on the current directory, one to jump to a bookmark, and one to list bookmarks. (It lacks all of the magic of z -- it doesn't try to learn how you work. It's entirely explicit.)