documents/dev/Windows.md

Windows Dev

Run (Windows+r)

  • shell:startup - open startup folder (current user)
  • shell:common - open startup folder (all users)

Z for folder navigation powershell

https://www.powershellgallery.com/packages/z/1.1.14
Install-Module -Name z -RequiredVersion 1.1.14

Neovim

Config directory: ~/AppData/Local/nvim/init.vim

# remove carriage return (displayed as ^M) at the end of each line
nmap <leader>cr :%s/\r$//<CR>

Conda & Torch

. /e/Work/miniconda3/Scripts/activate tts

# in powershell
conda activate tts

# to create environment
conda create --name <my-env>
conda create -n scriptsync python=3.12
conda activate scriptsync

# then install pytorch with cuda
# https://pytorch.org/get-started/locally/
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

# in python, to test for GPU
import torch
# should be true
torch.cuda.is_available()

# now you can run
whisper_timestamped --model tiny --device cuda --language en .\recording.m4a

run.bat - CMD batch script

@echo off

:launch
CD /D E:\\Work\scriptsync\services\transcription-container\container
call conda activate scriptsync
python server.py%*
pause
exit /b

Venv

virtualenv --python /c/Users/domin/AppData/Local/Programs/Python/Python310/python.exe venv
source ./venv/Scripts/activate

Package Manager

Chocolatey

chocolatey

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

Then (in elevated/admin powershell): choco install ack

Scoop

Scoop

In powershell, run

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression

Then: scoop install fd

Shortcuts

  • Powershell: Windows+x, a
  • shadowplay: Alt + f9 to start/stop record
  • windows screen/active window capture: Win+G

Install git to get Git Bash Here context menu

SSH

  • create admin authorized keys
    • ref
    • location: C:\ProgramData\ssh\administrators_authorized_keys
    • run admin powershell restart-service sshd
  • To make windows automatically open preferred shell:
    • ref
    • open regedit to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH
    • create new string name DefaultShell
    • set value to location of shell I:\git-sdk-64\usr\bin\zsh.exe

You can also check/set through CMD/Powershell

  • check using commandline reg query HKLM\SOFTWARE\OpenSSH /v DefaultShell
  • set to Powershell reg add HKLM\SOFTWARE\OpenSSH /v DefaultShell /d C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
  • or set to git-cmd reg add HKLM\SOFTWARE\OpenSSH /v DefaultShell /d E:\Program%20Files\Git\usr\bin\zsh.exe
  • make sure .zshrc inclues export PATH=$PATH:/e/Program\ Files/Git/usr/bin

Python

  • pip list -v shows where pip packages are installed
  • for python 3.X default location C:\Users\domin\AppData\Local\Programs\Python\Python310\Lib\site-packages
  • scripts will appear in C:\Users\domin\AppData\Local\Programs\Python\Python310\Scripts
  • virtualenv
    • pip install virtualenv
    • cd my-project
    • virtualenv --python C:\Users\domin\AppData\Local\Programs\Python\Python310\python.exe venv
    • .\venv\Scripts\activate to activate environment

Package Manager (old)

Git does not ship pacman with Git for Windows. To get a fully fledged package manager maintained environment, install the Git for Windows SDK. Reference.

Uses https://www.msys2.org/

Make pacman work for existing git

Requires running git bash as admin.

Locations

  • C:\Program Files\Git
  • I:\git-sdk-64
  1. Install Git for Windows SDK somewhere else. You'll need more than 3 GB of free space for that.
  2. Copy ${git-sdk}/usr/bin/pacman.exe to ${git}/usr/bin
  3. Copy ${git-sdk}/etc/pacman.conf and ${git-sdk}/etc/pacman.d to ${git}/etc
  4. Copy ${git-sdk}/var to ${git}/

You can now open your Git Bash and run pacman -S python, pacman -S tmux to install packages on your existing Git for Windows setup.

Change context menu reference

  • regedit
  • files HKEY_CLASSES_ROOT*\shellex\ContextMenuHandlers
  • desktop
    • HKEY_CLASSES_ROOT\Directory\Background\shell
    • HKEY_CLASSES_ROOT\Directory\Background\shellex\ContextMenuHandlers

aliases

alias work='cd /e/Work'
alias killnode='cmd "/C TASKKILL /IM node.exe /F"'
alias hide='ATTRIB +H'

alias ls='ls --color=auto --ignore={"NTUSER*","ntuser*","Sti_Trace.log"}'
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

alias dom='ssh dominick@192.168.0.100'
alias s='git status'
alias p='git pull origin $(current_branch)'
alias push='git push origin $(current_branch)'
alias gco='git checkout'
alias gc='git commit'
alias gd='if [ -f "package-lock.json" ]; then git diff ":!package-lock.json"; else git diff; fi'
alias b='git branch'
alias subl='C:/Program\ Files/Sublime\ Text\ 3/sublime_text.exe'
alias code='C:/Users/domin/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe'


function pport {
  netstat -ano | findstr :$1
}
function killpid {
  cmd "/C taskkill /PID $1 /F"
}
function current_branch() {
  ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  echo ${ref#refs/heads/}
}
function current_repository() {
  ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  echo $(git remote -v | cut -d':' -f 2)
}