setup: choco | wsl | visual studio
use: powershell | terminal shortcuts | commands
annoyances: run as administrator | copy and paste | resizing terminals | utf-8 | path
SETUP
Choco
To install choco, run PowerShell as administrator:
PS> set-executionpolicy bypass
PS> iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
PS> choco install -y 1password dropbox emacs googlechrome python3 steam sumatrapdf
Windows Subsystem for Linux
Put ssh keys at /home/USER/.ssh/id_rsa and /home/USER/.ssh/id_rsa.pub.
From the perspective of Linux, the Windows files are mounted at /mnt/c.
From the perspective of Windows, the Linux files are in C:\Users\USER\AppData\Local\lxss. To see these files in the File Explorer, you must check "Hidden Files" under the View menu. You must also go to View | Options | Change folder and search options, and under the View tab uncheck "Hide protected operating system files (Recommended)".
If I create a file from Windows in C:\Users\USER\AppData\Local\lxss, I cannot see the file from bash. If I try to create the same file in bash, I get an "Input/output error".
Visual Studio
download visual studio community
Install tools for developing in C++, C#, F#, Visual Basic, JavaScript, and TypeScript.
Use the start menu to launch Developer Command Prompt for VS 2017. If you inspect the %PATH%, you will find the locations for these tools:
cl | C++ compiler |
csc | C# compiler |
csi | C# REPL |
fsc | F# compiler |
fsi | F# REPL |
msbuild | build tool similar to Ant |
nmake | build tool similar to make |
tsc | TypeScript compiler |
vbc | Visual Basic compiler |
Emacs
Use choco to install Emacs and runemacs to launch as a GUI application.
The startup directory is C:\Users\USER\AppData\Roaming\.emacs.d.
Copy personal init files to that location. Add something like this to .emacs.d/init.el to get a better initial default directory:
(setq default-directory "C:/Users/USER")
USE
PowerShell
PowerShell supports both Unix style /foo/bar and Windows style C:\foo\bar paths.
The Windows file system is case-insensitive as are all cmd.exe and PowerShell command names.
PowerShell options are preceded by hyphens. Compare with cmd.exe which precedes options with slashes.
PowerShell options cannot be grouped behind a single hyphen as is sometimes the case for Unix commands. Also PowerShell options do not use double hyphens in front of options with multiple character names.
Most cmd.exe commands are available in PowerShell. However these are aliases to equivalent PowerShell commands. The options and possibly the behavior are different. In particular the slash option syntax is not supported. Use get-alias to see all the alias mappings in effect.
It is possible to run an actual cmd.exe command from the PowerShell in this manner:
PS> cmd.exe /c "fc foo.txt bar.txt"
Terminal Shortcuts
Tab completion gets the first match instead of filling out as much as can unambiguously be filled out.
Right and left arrow keys move the cursor. Up and down arrow keys navigate the history.
bash | cmd.exe/powershell windows | cmd.exe/powershell mac | |
---|---|---|---|
go to start of line | ^A | Home | fn← |
go to end of line | ^E | End | fn→ |
delete characters from cursor to end of line | ^K | Ctrl+End | fn^→ |
delete all character on line | ^A^K | ESC | |
xoff/xon | ^S/^Q | Ctrl+S/Ctrl+S |
Commands
cmd.exe | powershell | bash |
---|---|---|
cd | get-location | pwd |
cd | set-location | cd |
cls | clear-host | clear |
comp | diff -q | |
copy | copy-item | cp |
date | get-date set-date |
date |
del erase |
remove-item | rm |
dir /b | ls | |
dir | get-childitem | ls -l |
echo %path% | write-output $env:path | echo $PATH |
exit | exit | exit |
fc | compare-object -casesensitive (get-content .\foo.txt) (get-content .\bar.txt) | diff |
find | sls -simplematch | grep -F |
findstr | sls select-string |
grep -E |
findstr /s | grep -r | |
foo /? help foo |
foo -? get-help foo |
man foo |
md mkdir |
new-item -type directory | mkdir |
more | more | less |
move | move-item | mv |
ren rename |
rename-item | mv |
rd rmdir |
remove-item | rmdir rm -r |
$a = 1 echo $a |
a=1 echo $a |
|
set a=1 echo %a% |
$Env:a = 1 echo $Env:a |
export a=1 echo $a |
sort | sort-object | sort |
systeminfo | uname -a | |
type | get-content | cat |
measure-object -character -word -line | wc | |
xcopy robocopy |
copy-item -recurse | cp -R |
where | which | |
winver | cat /etc/*elease |
ANNOYANCES
Run As Administrator
If you need to do something with Administrator privilege—e.g.install a package—and your PowerShell does not currently have Administrator privilege, you must run a new PowerShell window. Right-click on the PowerShell icon and select "Run As Administrator". There is no password challenge, though Windows asks you to confirm you to confirm.
Copy and Paste
The Windows keyboard shortcuts for copy and paste are Ctrl+C and Ctrl+V. As of Windows 10 these shortcuts can also be used in a terminal.
To get them to work in a PowerShell or cmd.exe terminal, make sure that "QuickEdit Mode" and "Enable Ctrl key shortcuts" are checked in the "Properties" of the terminal.
Note that Ctrl+C will send an interrupt to the running program if no text is selected. If no text is selected and there is no running program, then Ctrl+C is a no-op.
Ctrl+C and Ctrl+V do not appear to work as copy and paste in a WSL bash terminal. If "QuickEdit Mode" is checked, then copy by selecting the region and typing ENTER. Paste by right-clicking anywhere in the terminal.
Ctrl+C and Ctrl-V also conflict with customary Emacs bindings. For cutting and pasting to and from Emacs, I set these custom bindings in .emacs.d/init.el:
(global-set-key "\C-cc" 'clipboard-kill-ring-save)
(global-set-key "\C-cv" 'clipboard-yank)
Resizing Terminals
It used to be necessary to go into the "Properties" of a terminal to resize it. As of Windows 10, it is possible to resize a terminal window like any other window. Thus one can drag a corner of the window or use Windows+Arrow key combinations.
UTF-8
The current character encoding of a terminal can be found in "Properties" under the "Options" tab.
The default encoding for the WSL bash terminal is UTF-8, but for cmd.exe and PowerShell it is Code Page 437, which is an 8-bit ASCII extension with characters for drawing boxes.
In cmd.exe and PowerShell the code page can be changed to UTF-8 like this:
DOS> chcp 65001
Running the above command causes more to stop working.
Path
The customary place for a program to install itself on Windows is C:\Program Files, or C:\Program Files (x86) in the case of 32 bit programs on a 64 bit version of Windows. If the program provides command line tools, it is responsible for updating the path environment variable, either for the system or the current user's account.
Editing either of these path values used to be painful because the text box in the Control Panel was too small. The process has been improved in Windows 10.
In Settings, search for "Environment Variables".
The WSL bash will not inherit these path values. To put the commands in the bash path, edit .bashrc. Bash will not execute a command such as tsc.exe unless the suffix is also used when the command is invoked.