Hacker News new | past | comments | ask | show | jobs | submit login
Shell Gamification (how I learn to use my shell aliases) (paulmckellar.com)
99 points by socmoth on Dec 3, 2012 | hide | past | web | favorite | 30 comments



I 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.


> 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.


> cls=clear # Yes, I started out in DOS

ctlr + l is your new best friend.


cmd + k (too)


cmd-k also clears the scrollback buffer. It's probably the single thing I miss most after moving back to linux from macOS.


You can bind Alt-K to Reset and clear in gnome-terminal's keyboard bindings.


Thank you!

My remaining minor complaint: alt-k loses the prompt.


Alt-K and Ctrl-l will solve that :)


> ctlr + l is your new best friend.

I use xterm (goes to check before I make an ass out of myself) and I'm utterly shocked this works. Amazing. Ctrl-l does indeed work.


alias ll='ls -halv'


If 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.


It'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...

(The interesting logic happens elsewhere, but the above template demonstrates that one can wrap git without too much trouble and without reducing functionality.)


For 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.


Tab 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


Neat! 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-differen...


It only looks like a hack until you understand Bash arrays.


I 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-...

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


awesome quote from article: "Why do something reasonable when you have the opportunity to do something ridiculous?" ... explains so much code ...


That for me also summed up nicely what separates a coder from a hacker. :]


Here'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'


Why the piping into more?


I 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.


Passing -F to less causes it to automatically quit if the file can be displayed on one screen.


Hah, 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.


This 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"


I 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.


By 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"


[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.)


Instead of creating aliases, I'm using z (https://github.com/rupa/z) for that. You use it instead of cd to navigate to the most frequently used directories anywhere.


Thanks 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.




Applications are open for YC Winter 2020

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: