tools

git console: changing brach interactively

Some time ago I wrote about some helpful script that let me copy branch name without mouse. Later on I wrote about some simple console menu in Powershell. The second one seems to be a far better option here. Here’s the code:

#uncomment if you don't have ps-menu (powershellget is needed)
#install-module ps-menu -scope currentuser

$selection = menu (iex "git branch")
if ($selection -ne $null)
{
    $branch = $selection.Trim(" ", "*")
    iex "git checkout $branch"
}

Here is how it works:

branching

Advertisements
tools

Console aliases in Windows – the better approach

A big advantage of working in console mode is ability to create aliases. First you can easily shorten a command with a lot of switches. You can also automate your job by creating a script file and then set an alias for that script.

The default way of creating aliases in Windows is DOSKEY:

doskey np=notepad++.exe $*

The weak point of it is that you have to reassign them after restarting console window. There are ways for automating that using cmd.exe /k switch or using system
registry (see https://gist.github.com/vladikoff/38307908088d58af206b both article and comments).

There is also a buil-in option for ConEmu:
http://superuser.com/questions/556248/creating-alias-in-conemu

But all in all this is weak, as always you have to do two things: establish an
alias and then save it in some file for future use.

Alternative (better!) solution

I can sell you my way of dealing with aliases. I don’t use DOSKEY. Instead, I have a folder, i.e. C:\Tools\Aliases and there. I have a lot of *.cmd or *.ps1 files. The trick is that the folder is in my PATH variable.
Let’s say I have there a !notes.cmd command that runs:

vim c:\documents\notes01.txt

Then I can type ‘!notes’ and it runs “!notes.cmd” file that results in openning my temporary notes file. Obviously TAB autocompletion works fine. ‘!’ in the beginning lets me filter out my own aliases. I have also “!editaliases.cmd” for editing my aliases:

vim c:\tools\aliases\

aliases
Aliases are ready to use just after adding/editing them.
Other advantages:

  • no fancy escape characters (doskey defines its own list)
  • I can assing a whole script to an alias with one file
  • works in every console and emulator
Powershell, tools

Simple interactive console menu in Powershell

Personally I am a kind of console-freak. If possible, I would do everything in terminal. But in my case loving terminal is not about remembering all the different switches and options of console commands, but rather presenting things in a simple, readable manner, without fireworks. And most of all, navigation must be fast and comfortable. That’s why I prefer choosing options from simple menu than getting through command documentation and juggling with switches/parameters. That’s the course set out by yeoman for example.

I tried to find an easy way of building command-line menus but I couldn’t so I ended up with my own solution. It’s based on Powershell. I’m sharing it here in case you wanted to use it as well.

As we all know a picture is worth a thousand words:
example1

You can still find the code on github: https://github.com/chrisseroka/ps-menu/

The script is really short but the best way you can use it is to install it
with PowerShellGet from https://www.powershellgallery.com/

install-module -name ps-menu

You can also copy-paste the code from ps-menu.psm1 file in case you wanted to have everything in one place.