Skip to content

Instantly share code, notes, and snippets.

View bsdayo's full-sized avatar
💭
Reimagining my life

bs bsdayo

💭
Reimagining my life
View GitHub Profile
@bsdayo
bsdayo / pwsh-bash-completion.ps1
Created November 12, 2024 23:47
Make Bash's autocompletion available to PowerShell on Linux.
# Add this snippet to your $PROFILE to make Bash's autocompletion available to PowerShell on Linux.
# Warning: adds ~500ms initialization time.
# References: https://brbsix.github.io/2015/11/29/accessing-tab-completion-programmatically-in-bash/
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/register-argumentcompleter
# Find all commands
$commands = bash -c 'source /usr/share/bash-completion/bash_completion && complete' | awk '{ print $NF }'
$commands += ls /usr/share/bash-completion/completions
$commands | ForEach-Object {
@bsdayo
bsdayo / internet-access.service
Created November 12, 2024 13:09
Systemd service to check Internet access
[Unit]
Description = Check Internet access
After = network-online.target
[Service]
Type = oneshot
ExecStart = /bin/bash -c "until ping -c 1 www.baidu.com; do sleep 1; done;"
[Install]
WantedBy = network-online.target
@bsdayo
bsdayo / capture-stdout-stderr.ps1
Created November 11, 2024 02:43
Capture both stdout and stderr to separate variables
$err = ($out = somecommand) 2>&1
# Type of $out is string[] if present
# Type of $err is ErrorRecord if present
@bsdayo
bsdayo / make-shortcut.ps1
Last active May 21, 2024 01:23
Super "Windows shortcut" maker with embedded icon
param(
[Parameter(Mandatory)] [string] $Command,
[Parameter(Mandatory)] [string] $IconFile,
[string] $Output,
[switch] $Keep
)
(Get-Content -Encoding UTF8 template.c) -replace "COMMAND_PLACEHOLDER", ($Command -replace '\\', '\\') | Out-File -Encoding UTF8 temp.c
"icon ICON `"$($IconFile -replace '\\', '\\')`"" | Out-File -Encoding UTF8 temp.rc