Skip to content

Latest commit

Β 

History

History
345 lines (233 loc) Β· 11.9 KB

README.md

File metadata and controls

345 lines (233 loc) Β· 11.9 KB

FAQ

Installation

Basically following codes will be done in PowerShell

  1. Download the windows helper binaries from GitHub releases or uploaded artifacts in each workflow summary
  2. New session of pwsh
    ./winit-conf.exe run
    
    Install-Module -Name PSFzfHistory
    # $PROFILE is an "Automatic Variables", not ENV
    # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.4
    ./winit-conf.exe generate -path="powershell/Profile.ps1" > "$PROFILE"
    
    ./winit-reg.exe list
    ./winit-reg.exe run --all
  3. Install some tools
    # Basically this may be same output of above `winit-conf.exe` log
    # Pick-up the winget-*.json outputs
    $env:TMP
    # => C:\Users\YOU\AppData\Local\Temp
    
    winget import --import-file "C:\Users\YOU\AppData\Local\Temp\winitRANDOM1\winget-pkgs-basic.json"
    # Optional
    winget import --import-file "C:\Users\YOU\AppData\Local\Temp\winitRANDOM2\winget-pkgs-storage.json"
    winget import --import-file "C:\Users\YOU\AppData\Local\Temp\winitRANDOM3\winget-pkgs-entertainment.json"
  4. Remove needless pre-installed tools. Pick up from bulk-uninstall.ps
  5. Change Dropbox storage path from C:\Users, default path made problems in System Restore.
    See https://zmzlz.blogspot.com/2014/10/windows-dropbox.html for detail
  6. Enable Bitlocker and backup the restore key

How to print windows ENV?

AFAIK, %ENVNAME% can be replaced in PowerShell as follows

~ psh
> $env:APPDATA
C:\Users\YOU\AppData\Roaming

~ psh
> $env:TMP
C:\Users\YOU\AppData\Local\Temp

And golang source code is much helpful

How to install WSL2?

winget does not support it, run as follows

wsl.exe --install --distribution "Ubuntu-24.04"

PowerShell startup is too slow

Loading personal and system profiles took 897ms.
  1. Make sure you are using PSFzfHistory, not PSFzf
  2. Make sure pwsh -NoProfile is fast
  3. Restart the pwsh, if it is fast, cache maybe generated. The slow may happen when updated windows and/or the runtimes. (I guess)
  4. Do NOT consider about ngen.exe solution as Googling say. It looks old for me.

Reason: ngen.exe cannot compile latest pwsh

One more noting, if you cannot find ngen.exe, dig under "C:\Windows\Microsoft.NET\Framework" as "C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe"

How to export winget list?

winget export --output "\\wsl.localhost\Ubuntu-24.04\home\kachick\repos\dotfiles\config\windows\winget-pkgs-$(Get-Date -UFormat '%F')-raw.json"

It may be better to remove some packages such as Mozilla.Firefox.DeveloperEdition.

Which programs excluded winget-pkgs are needed?

History substring search in major shells for Windows

Why avoiding winget to install Firefox Developer Edition?

No Japanese locale is registered in winget yet, official installer is supporting.

How to open current directory in WSL2 with Windows Explorer?

In WSL shell

explorer.exe .

How to move on Windows folder from WSL2?

z "$(wslpath 'G:\GoogleDrive')"

Login shell has been broken in WSL2

wsl --user root

I forgot to backup Bitlocker restore key πŸ˜‹

https://account.microsoft.com/devices/recoverykey may help

How to write PowerShell scripts?

How to get helps for PowerShell commands as cmd --help in Unix?

Get-Help -Name New-Item

Or visit to https://learn.microsoft.com/ja-jp/powershell/module/microsoft.powershell.management/

How to realize mkdir -p in PowerShell?

No beautiful ways, I think. Read https://stackoverflow.com/questions/19853340/powershell-how-can-i-suppress-the-error-if-file-alreadys-exists-for-mkdir-com

How to run PowerShell scripts in this repo?

If you faced following error, needed to enable the permission from Administrator's PowerShell terminal

.\windows\scripts\enable_verbose_context_menu.ps1: File \\wsl.localhost\Ubuntu-24.04\home\kachick\repos\dotfiles\windows\scripts\enable_verbose_context_menu.ps1 cannot be loaded. The file \\wsl.localhost\Ubuntu-24.04\home\kachick\repos\dotfiles\windows\scripts\enable_verbose_context_menu.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.

Executing loccal scrips just requires "RemoteSigned", but in wsl path, it is remote, so needed to relax more.

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    Unrestricted
 LocalMachine       Undefined

After completed tasks, disable it as follows

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

History in PowerShell does not work...

If PowerShell in WindowsTerminal displaying as below,

PowerShell 7.3.6
Cannot load PSReadline module.  Console is running without PSReadline.

I have faced this problem when called Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser.
Try to set the permission as Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

microsoft/terminal#7257 (comment)

Some PowerShell scripts did not change windows behaviors

https://answers.microsoft.com/en-us/windows/forum/all/windows-registry-changes-is-a-restart-always/e131b560-1d03-4b12-a32c-50df2bf12752

After registry editing, needs to restart windows or the process

Why are you still using Google Japanese Input? Why don't you prefer Microsoft IME?

Pros for Microsoft IME

  • Preinstalled by Windows
  • It is having cloud translations now (Called as "δΊˆζΈ¬ε€‰ζ›")

Cons for Microsoft IME

  • Needed to tab, not in space to get date as "きょう"
  • No way to get date with ISO 8601 format

How to completely disable Microsoft IME after installed Google Japanese Input?

#300 is the steps.

Containers?

I now prefer podman over docker and singularity.
It needs special WSL distribution. How to run it from standard WSL ubuntu is written in this document.
Make sure you are using podman binary as podman-remote, nixpkgs product does not satisfy.
This repository aliases podman command to mise installed binary.

This is an worked example

# WSL - Ubuntu

podman system connection add --default podman-machine-default-user unix:///mnt/wsl/podman-sockets/podman-machine-default/podman-user.sock

# Since Ubuntu 24.04, you may need to update the usergroup of socket file
sudo chgrp "$(whoami)" /mnt/wsl/podman-sockets/podman-machine-default/podman-user.sock

# See wsl.nix for detail
# TODO: Update cmd/wsl-init
sudo systemctl enable ~/.config/systemd/user/mnt-wsl-instances-ubuntu24.mount --now

cdg irb-power_assert
podman run --volume /mnt/wsl/instances/ubuntu24/"$(pwd)":/workdir --workdir /workdir -it ghcr.io/ruby/ruby:master-dev-jammy-amd64-da66abc584a9a33693d1b5bbf70881a008b0935d

After updating podman from 4.x -> 5.0.0, cannot do any operation even if the setup VM

Error: Command execution failed with exit code 125 Command execution failed with exit code 125 Error: unable to load machine config file: "json: cannot unmarshal string into Go struct field MachineConfig.ImagePath of type define.VMFile"

It relates to podman#22144.
And might be happen in future major updating and the schema changes. So this snippet may help you.

Abandon current VM, images, containers. Then following steps are the how to fix

winget uninstall --exact --id RedHat.Podman-Desktop
winget uninstall --exact --id RedHat.Podman
wsl --list
wsl --unregister podman-machine-default
cd ${Env:USERPROFILE}\.config\containers\podman\machine\wsl\
Remove-Item .\podman-machine-*
winget install --exact --id RedHat.Podman
winget install --exact --id RedHat.Podman-Desktop

And create the new podman-machine-default

How mount project volumes in podman-remote

Track the official discussion, but there are no simple solutions for now.
This repository provides a mount based solution, mount from another instance as /mnt/wsl/..., then podman-machine also can access there.

  1. Ubuntu: Activate the home-manager with --flake '.#kachick@wsl'.
  2. Look the definitions, it includes how to mount with systemd.
  3. podman-machine: Make sure podman-machine can read there ls /mnt/wsl/instances/ubuntu24/home
  4. Ubuntu: cdg project_path
  5. Ubuntu: podman run -v /mnt/wsl/instances/ubuntu24/"$(pwd)":/workdir -it ghcr.io/ruby/ruby:master-dev-76732b3e7b42d23290cd96cd695b2373172c8a43-jammy

How SSH login to podman-machine from another WSL instance like default Ubuntu?

WSL - Ubuntu

Get pubkey

cat ~/.ssh/id_ed25519.pub | clip.exe

WSL - podman-machine

Register the Ubuntu pubkey

vi ~/.ssh/authorized_keys

Host - Windows

Get podman-machine port number

podman system connection list | Select-String 'ssh://\w+@[^:]+:(\d+)' | % { $_.Matches.Groups[1].Value }

WSL - Ubuntu

You can login with the port number, for example 53061

ssh user@localhost -p 53061

How mount client volume with podman-remote

After SSH setup as above steps

In WSL - Ubuntu

rclone config create podman-machine sftp host=localhost port=53061 publickey=~/.ssh/id_ed25519.pub user=user
# Make sure the connection
rclone lsd podman-machine:/home/user

z project_path 
rclone mount --daemon "podman-machine:repos/$(basename "$(pwd)")" .

# If you want to unmount, use specific command instead of kill the background job
# 
# Linux
fusermount -u /path/to/local/mount
# OS X
# umount /path/to/local/mount

How oneshot sync source code for podman-remote

This is just a note, prefer rclone mount for easier

After SSH setup as above steps

In WSL - Ubuntu

z project_path

rclone sync --progress . "podman-machine:repos/$(basename "$(pwd)")"