windows

Symbolic Links in Windows

Since Windows Vista we have possibility to create symbolic links on Windows. Yay!

To do that, we have command mklink in Command Prompt:

C:\Users\jj\Desktop>mklink link_to_some_file.txt c:\Dropbox\some_file.txt
symbolic link created for link_to_some_file.txt <<===>> c:\Dropbox\some_file.txt

Symbolic link is not a shortcut. However, its icon desktop looks the same:

link and shortcut icons in Windows

You can find out whether it is a link or shortcut by looking on the properties (left – link, right – shortcut):

link vs shortcut in Windows

You can also check it from the command prompt:
C:\Users\jj\Desktop>dir
Volume in drive C has no label.
Volume Serial Number is A425-1CEF

Directory of C:\Users\jj\Desktop

11/15/2013 10:36 AM <DIR> .
11/15/2013 10:36 AM <DIR> ..
11/15/2013 10:35 AM <SYMLINK> link_to_some_file.txt
11/15/2013 10:36 AM 921 some_file - Shortcut.lnk
2 File(s) 921 bytes
2 Dir(s) 15,738,155,008 bytes free

OT: Don’t you think dir command is to verbose? Who needs e.g. Volume Serial Number each time during listing directory?

In PowerShell, you need to use following command: cmd /c mklink (precede mklink with cmd /c).

I use it for my PowerShell config file. Original one is in Dropbox and symlink just point to it from MyDocuments directory (where it has to be, to be applied by PowerShell).


Windows PowerShell profile

Windows PowerShell is very powerful tool. It contains many useful commands. One of my favorite features is possibility to use some well-known bash commands such as: ls or pwd, which are missing in Windows Command Prompt. The cool thing is the fact, that PowerShell contains combination of Windows Command Prompt and Bash shell commands. E.g. for copying you can use copy (Windows) and cp (Bash).

You can also have personal configuration file (like .bashrc in Unix) to set some persistent settings. To find out, where it is located use command:

PS C:\> echo $PROFILE
C:\Users\jj09\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

I needed to create directory ‘WindowsPowerShell’ and profile file before adding some custom settings. Additionally, I needed to enable scripts on my system (it is disabled by default).

PS C:\> Set-ExecutionPolicy RemoteSigned

More info about Execution Policies can be found here.

My Microsoft.PowerShell_profile.ps1 file:

set-alias subl "C:\Program Files\Sublime Text 2\sublime_text.exe"
set-alias grep select-string
set-alias ssh New-PSSecureRemoteSession
set-alias sh New-PSRemoteSession
set-alias l ls

There is also ‘Power’ version of PowerShell called ISE (Integrated Scripting Environment). Be aware, that it has different profile file (for me it is: C:\Users\jj09\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1). You can check it with the same command like for standard PowerShell (echo $PROFILE). Here is a list of top 10 killer features, which are in ISE, but not in standard PS (Intellisense is my favorite).

PowerShell-autocomplete

Disadvantage of PowerShell is its loading time. Windows Command prompt loads instantaneously, but PS need ~1 second. It is even worse in case of ISE, which needs ~3 seconds (on my Thinkpad X220: i5/8GB/SSD).

You can add custom configuration to Windows Command Prompt too. To do that you need to run command prompt with some arguments.


dotNetConfPL – online conference for .NET developers

Together with Michal Franc and Pawel Sawicz we are organizing online conference for .NET Developers: dotNetConfPL. It will take place on October 12 (3pm-10pm UTC+2), on the Internet! We have many great speakers and hot sessions.

Attendees will be able to ask questions through dotNetConfPL2013 room on JabbR.

Today, we have over 500 registered users! Additionally, during the conference we will give away 6 ReSharper licenses (thank you JetBrains).

Registration is not obligatory, but only registered users will have chance to win ReSharper licenses.

See you there!


scriptcs – C# in console

It was always bothering me, when I wanted to run one simple command, and I needed to create new C# console project in Visual Studio to do that. With scriptcs I can finally do that in console. Project scriptcs allows you to run single commands and also C# script files.

Installation

The easiest way to install scriptcs is Chocolatey (‘apt-get’ for windows). If you didn’t hear about it, you should definitely try it out. To install Chocolatey run the following command in console:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin

Once you have Chocolatey installed, you can install scriptcs:

cinst scriptcs

Chocolatey will install scriptcs to %APPDATA%\scriptcs\. You need to update your PATH accordingly, to easily run it from command line.

Getting started

Once scriptcs is installed and added to your PATH, you can run it with scriptcs command:

C:\> scriptcs
scriptcs (ctrl-c or blank to exit)

> var message = "Hello, world!";
> Console.WriteLine(message);
Hello, world!
>

C:\>

You can also create a script hello.csx:

var message = "Hello, world!";
Console.WriteLine(message);

And run it from command line:

C:\>scriptcs hello.csx
Hello, world!

You can find more about scriptcs on scriptcs.net.

EDIT: You don’t even need Console.WriteLine to print variables (thanks Filip W.):

C:\>scriptcs
scriptcs (ctrl-c or blank to exit)

> var message = "Hello, scriptcs!";
> message
Hello, scriptcs!
> int four = 2 + 2;
> four
4
>


Tools I use everyday

I published a list of tools I use everyday. Maybe someone will find something what is useful for him, but never heard about.

I will try to keep it up to date and it will be always accessible through http://jj09.net/tools.

Not all tools are multi-platform. For now, the list is only for Windows. Maybe sometime in the future I will publish also “Mac Specific” tools.