Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCM Breeze feature - Shortcut to files from ls, and wrap common shell commands #44

Closed
ndbroadbent opened this issue Aug 15, 2012 · 11 comments

Comments

@ndbroadbent
Copy link
Member

I've just finished some work that integrates the numeric shortcuts into the rest of your shell commands.
So, as well as shortcuts for files in git status, you can now also get shortcuts to files from the output of ls. I was using ll as an alias for ls -l, but now I've turned ll into an SCM Breeze function that gives the following output:

ll

After typing ll, you can use any of the following commands with the numbered shortcuts:

  • vim, emacs, gedit, cat, rm, cp, mv, ln, ls, cd

For example, let's say you wanted display the contents of scmbrc.example - now you can just type cat 11.

I've tested it out as much as I can, but I'm sure we will run into some strange issues at some point.
If you would like to help test it, please update scm_breeze from the master branch and let me know how it works for you.
Also let me know if you have any suggestions for commands that should be added to the list above.

Thanks!

@ghthor
Copy link
Member

ghthor commented Aug 15, 2012

Very interesting idea! I'll see if anything breaks for me.

@ghthor
Copy link
Member

ghthor commented Aug 15, 2012

tacos@tacopalace ~/.scm_breeze [master±]$ ll
total 56
drwxr-xr-x 6 ghthor users  4096 Jun 13 03:04 [1]  lib
drwxr-xr-x 4 ghthor users  4096 Nov  1  2011 [2]  test
-rw-r--r-- 1 ghthor users    41 Nov  1  2011 [3]  Gemfile
-rw-r--r-- 1 ghthor users   100 Nov  1  2011 [4]  Gemfile.lock
-rw-r--r-- 1 ghthor users  1097 Jan 30  2012 [5]  LICENSE
-rw-r--r-- 1 ghthor users 11370 Aug 15 09:05 [6]  README.markdown
-rw-r--r-- 1 ghthor users   317 Nov  1  2011 [7]  Rakefile
-rw-r--r-- 1 ghthor users  2993 Aug 15 09:05 [8]  git.scmbrc.example
-rwxr-xr-x 1 ghthor users   906 May  8 23:01 [9]  install.sh
-rw-r--r-- 1 ghthor users   607 May  8 23:01 [10] scmbrc.example
-rw-r--r-- 1 ghthor users   919 Aug 15 09:23 [11] scm_breeze.sh
-rwxr-xr-x 1 ghthor users   219 May  8 23:01 [12] uninstall.sh
tacos@tacopalace ~/.scm_breeze [master±]$ cd 1
bash: /home/ghthor/.scm_breeze/�[01: No such file or directory
bash: $'34mlib\E[0m': command not found

Same thing is happening with vim. If this means anything cat worked as expected.

Also when my shell opens I'm now told

which: no cd in (all my paths)

@ndbroadbent
Copy link
Member Author

Hey, thanks so much for your help! I've pushed some fixes for shell builtins, and ensured colors are stripped from ls with the color=never problem. Can you please update and try again?

@ghthor
Copy link
Member

ghthor commented Aug 15, 2012

Working great. This is awesome!

@ndbroadbent
Copy link
Member Author

Good to hear! Thanks!

@jchain
Copy link

jchain commented Aug 15, 2012

I like this feature and am using it. BTW, do you think it will be a good idea to have the numeric shortcut for git branch and git checkout? I normally have a bunch of branches, switching back and forth is tedious even with the aid of bash completion. I would like to type git branch or gb to list the local branches labeled by numbers and then type gco 1 to change to the first branch. Thanks!

@ndbroadbent
Copy link
Member Author

Hey, I think that's a great idea, and I've just pushed support for git branch shortcuts up to the master branch. Instead of running git pull this time, please run update_scm_breeze, which will also add the new aliases to your git.scmbrc config file.

Numbered shortcuts are now shown for git branch, and the following aliases for branch commands:

  • gb = git branch
  • gba = git branch -a (shows all branches from remotes)
  • gbm = git branch -m (move a git branch (rename) )
  • gbd = git branch -D (delete a branch)

All of these aliases work with the numbers from git branch, so you type things like: gco 1, gbd 2, gbm 3 new_branch_name, etc.

Thanks for this idea, it really is useful!

@ndbroadbent
Copy link
Member Author

Note: You should be able to run the update_scm_breeze command from anywhere. SCM Breeze sets it up as a function when it's loaded.

@jchain
Copy link

jchain commented Aug 15, 2012

I have my customized cd listed below which conflicts with scm_breezed cd

cd() {
   MAX=10
   LEN=${#DIRSTACK[@]}

   if [ $# -eq 0 ] || [ "$1" = "-" ]; then
      builtin cd "$@"
      pushd -n $OLDPWD > /dev/null
   else
      local len=`expr match "$1" '^-[0-9]*'`
      if [ $len -ge 2 ]; then
         builtin pushd +${1:1} > /dev/null
      else
         pushd "$@" > /dev/null || return 1
      fi
   fi

   if [ $LEN -gt 1 ]; then
      for i in `seq 1 $LEN`; do
         eval p=~$i
         if [ "$p" = "$PWD" ]; then
            popd -n +$i > /dev/null
            break
         fi
      done
   fi

   if [ $LEN -ge $MAX ]; then
      popd -n -0 > /dev/null
   fi

   # Default action: list files
   ls
}

Can I specify which bash commands to be scm_breezed? I definitely like my vim to be scm_breezed but might not others. Normally I use mc (midnight-commander) to move around and to do common file operations. I have noticed that in .git.scmrc there is a line that I can comment out to disable all alias.

@ndbroadbent
Copy link
Member Author

Ah, I see, you are already using numbers for your custom cd.
Sure, I just pushed a change so you can now edit the commands in your git.scmbrc file, and remove 'cd' from the list.
Again, you'll need to update using update_scm_breeze

@jchain
Copy link

jchain commented Aug 15, 2012

Awesome! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants