Skip to content
On this page

Cygwin

  • todo / add / merge cygwin setup instructions
  1. Install cygwin
  2. Install cygwin packages
  3. ps1 aliases $profile
  4. cygwin aliases / bashrc
  • .bash_alias.cy.sh
  • colors
  • git
  • completion / suggestion

Profile / Alias

ps1
<#
@Vite-Press-Docs.git
#> 
# If Interactive, set prompt to show ssh connection and current directory
# if ($null -ne $Host.UI) {
if ($Host.UI.RawUI.WindowTitle) {
  <# region cygwin initialize #>
  if(Test-Path "C:\cygwin64\bin\"){
    New-Alias -Name tree -Value c:/cygwin64/bin/tree.exe
    New-Alias -Name bash -Value c:/cygwin64/bin/bash.exe
    New-Alias -Name zsh -Value c:/cygwin64/bin/zsh.exe
  }
  #    todo   # if(Test-Path "C:\Program Files\JetBrains\WebStorm 2020.3\bin"){
    # and jetbrains
    <# end region cygwin initialize #>
    #    New-Alias -Name jc-open-network -Value "C:\Windows\explorer.exe '::{7007ACC7-3202-11D1-AAD2-00805FC1270E}'"
    function jc-open-network(){
      & C:\Windows\explorer.exe ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
      # todo add how to check public / private network / ethernet thing
      # maybe monitor settings
    }
    <# region conda initialize #>
    # conda slows down powershell way too much!
    # !! Contents within this block are managed by 'conda init' !!
    # If (Test-Path "C:\ProgramData\mambaforge\Scripts\conda.exe") {
      If (Test-Path "C:\Users\Jason\miniforge3\Scripts\conda.exe") {
        # dont think alias work that way... 
        function init-conda {
          # out dated i believe with minimamba.
          # 
          (& "C:\Users\Jason\miniforge3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
          
          # & "C:\ProgramData\mambaforge\Scripts\conda.exe" "shell.powershell" "hook" | Out-String | ?{$_} | Invoke-Expression
        }
        # New-Alias -Name init-conda -Value '&("C:\ProgramData\mambaforge\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression'
        # invoke shell.. but let's just add an alias like init-conda
        <#
        New-Alias -Name init-conda -force -Value '&("C:\ProgramData\mambaforge\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression'
        init-conda
        conda env list
        remove-alias -Name init-conda
        #>
        # (& "C:\ProgramData\mambaforge\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
      }
      If (Test-Path c:/Users/Jason/Downloads/controlmymonitor/ControlMyMonitor.exe) {
        # "DELL S3220DGF"
        function set-hdmi-1 {
          # vcp code 60
          cmd.exe /c 'c:/Users/Jason/Downloads/controlmymonitor/ControlMyMonitor.exe /SetValue "DELL S3220DGF" 60 17'
        }
        function set-hdmi-2 {
          # vcp code 60
          cmd.exe /c 'c:/Users/Jason/Downloads/controlmymonitor/ControlMyMonitor.exe /SetValue "DELL S3220DGF" 60 18'
        }
    }
      function open-sshconfig {
        code %HOME/.ssh/config
        # convert to alias later. i guess this must be in vscode task or keyboard shortcut...
      }
      function open-cdrepos {
        code (&"C:\Program Files\Git\bin\git.exe" rev-parse --show-toplevel )
        # convert to alias later. i guess this must be in vscode task or keyboard shortcut...
      }
      
      function sstart-repo-code {
        code (&"C:\Program Files\Git\bin\git.exe" rev-parse --show-toplevel )
        # convert to alias later. i guess this must be in vscode task or keyboard shortcut...
      }
      function sstart-repo-webstorm {
        &"C:\Program Files\JetBrains\WebStorm 2020.3\bin\webstorm64.exe" (&"C:\Program Files\Git\bin\git.exe" rev-parse --show-toplevel )
        # convert to alias later
      }
      <# end region conda initialize #>
      Import-Module PSReadLine
      Set-Alias git "C:\Program Files\Git\cmd\git.exe" # not sure if this will fix it though...
      function prompt{
        $cwd = $executionContext.SessionState.Path.CurrentLocation
        $ssh = ""
        
        if ($env:SSH_CONNECTION) {
          $ssh = "ssh://"
        }
        Write-Host "# $ssh$Env:Username@$env:COMPUTERNAME" -ForegroundColor DarkGray
        Write-Host "# $cwd" -ForegroundColor DarkGray
        Write-Host $env:CONDA_PROMPT_MODIFIER"PS >" -ForegroundColor DarkGreen -NoNewline
        # Write-Host "PS >" -ForegroundColor DarkGreen -NoNewline
        Write-Host $('' * ($nestedPromptLevel + 1)) -ForegroundColor DarkGray -NoNewline
        return " "
      }
    }

<#
cygwin
function cd-current-file() {
    cd $(dirname $(cygpath -u "$1"))
}
#>
sh
#/c:/cygwin64/bin/bash.exe
#/usr/bin/env bash.exe
# works better without it i guess
# export PATH="/usr/bin:$PATH"
alias igrep='grep -i --color=auto'
alias grep='grep --color=auto'
alias egrep='grep -E --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}'
alias fgrep='grep -F --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}'
alias tree=/bin/tree.exe
alias bash=/bin/bash.exe
alias ssh=/bin/ssh.exe
alias git=/bin/git.exe
alias wget=/bin/wget2.exe
alias curl=/bin/curl.exe
alias l='ls -lah'
alias la='ls -lAh'
alias ll='ls -lh'
alias ls='ls --color=tty'
alias lsa='ls -lah'
alias md='mkdir -p'
alias rd=rmdir
alias which-command=whence
alias _='sudo '
alias rsync='rsync -e "/bin/ssh.exe"'
alias df='df -h'
alias du='du -h'
alias dmesg='dmesg -T'
alias apt-install='/cygdrive/g/HyperVImages/utils/setup-x86_64.exe'
alias start='/cygdrive/c/Windows/explorer.exe'
alias jc-code='code -r' #open in current window
alias jc-find-files='find . -type f -name'
alias gcm='git fetch origin;git checkout main;git fetch origin --prune'
alias crlfGit='git config --global core.autocrlf input'
# true might be better for windows cygwin....
#alias crlfGit='git config --global core.autocrlf true'
# true is for crossplatform...
# need to verify this one:
alias crlfRm='find . -type f -exec sed -i \'s/\r$//\' {} \;'
# remember VSCode can add to path
# TERM=xterm-256color + tmux

function jc-findFiles {
  local filename=$1 # must be double quoted
  local directory=${2:-"."}
  find $directory -type f -name $filename \
  -not \( -path "./node_modules/*" -prune \) \
  -not \( -path "*/.*" -prune \)
}
function jc-chmod-shells {
  local filename=${2:-"*.sh"}
  local directory=${2:-"."}
  find $directory -type f -name $filename -not \( -path "./node_modules/*" -prune \) \
  -not \( -path "*/.*" -prune \) \
  -exec echo {} \; \
  -exec chmod +x {} \;
}
function jc-gh-chmod-shells {
  local filename=${2:-"*.sh"}
  local directory=${2:-"."}
  find $directory -type f -name $filename -not \( -path "./node_modules/*" -prune \) \
  -not \( -path "*/.*" -prune \) \
  -exec git update-index --chmod=+x {} \; \
  -exec chmod +x {} \;
}

function cd-current-file() {
    cd $(dirname $(cygpath -u "$1"))
}

#####
# mac: todo add to docs
#alias webstorm='open -na "WebStorm.app"'
#####

# should add chmod+x and git chmod+x
## src/file-folder-glob-utils/posix/find-chmod-sh-files/find-chmod-sh-files.test.sh
# https://stackoverflow.com/questions/19737525/find-type-f-exec-chmod-644

# some find / sed / awk
# remember to add ls_colors
## dircolors -b > ~/.bash_dircolors.cy.sh
## later just use zsh... with oh-my-zsh
function wcd(){
    cd $(wslpath $1)
}

ZSH

Cygwin / MobaXterm

bash
# soft link i believe. hard link might make more sense
ln -s /cygdrive/c/Users/`whoami`/.ssh/config ~/.ssh/config
ln -s /cygdrive/c/Users/`whoami`/.ssh/id_ed25519 ~/.ssh/id_ed25519
ln -s /cygdrive/c/Users/`whoami`/.ssh/id_ed25519.pub ~/.ssh/id_ed25519.pub
bash
#mkdir -p ~/.ssh
ssh-keygen -t ed25519
#ssh-keygen -t ed25519 -C "comment"
#ssh-keygen -q -t ed25519 -f ~/.ssh/id_ed25519 -N ""

Rsync

from cygwin to linux

  • must install cygwin ssh.exe
  • ssh config might need to be in cygwin format
bash
mkdir -p ~/.ssh
ln -s /cygdrive/c/Users/`whoami`/.ssh/config ~/.ssh/config
rsync --dry-run -v -e "/bin/ssh.exe" ~/test-rsync.txt /tmp/test-rsync.txt

from linux to cygwin / windows

bash
# cygwin to cygwin worked here...
# --rsync-path
ssh -o "RequestTTY no" localhost hostname
rm -f /tmp/test-rsync.txt
rm /tmp/test-rsync.txt
rsync /home/`/bin/whoami`/test-rsync.txt /tmp/test-rsync.txt; cat /tmp/test-rsync.txt
rsync --dry-run -v /home/`/bin/whoami`/test-rsync.txt localhost:/tmp/test-rsync.txt; cat /tmp/test-rsync.txt
rsync -v /home/`/bin/whoami`/test-rsync.txt localhost:/tmp/test-rsync.txt; cat /tmp/test-rsync.txt

shebang

bash
# todo
# try


.bash_profile
.bashrc

printenv PATH |grep /usr/bin
printenv PATH > printenvPATH.csv
code printenvPATH.csv
# replace : with \n
sed -i 's/:/\n/g' printenvPATH.csv

printenv PATH | sed 's/:/\n/g'
export PATH="/usr/bin:$PATH"

# system variables defn ontop

Pkg from Node

  • convert / alias perhaps
  • wrap alias rsync to convert from ps1

Find w/o everything

bash
find . -type f -name "*.sh"
find c:/ -type f -name "webstorm64.exe"
find c:/ -type f -name "webstorm64.exe" -print -quit
find c:/ -maxdepth 2 -type f -name "webstorm64.exe"


find /path/to/directory -type f -name "webstorm64.exe" -print | parallel --pipe -k -L 5 head

Network Connections

yaml
tags: ["Network Adapters",Network Connections]
powershell
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Network Connections.lnk")
$Shortcut.TargetPath = "explorer.exe"
$Shortcut.Arguments = "::{7007ACC7-3202-11D1-AAD2-00805FC1270E}"
$Shortcut.Save()
powershell
# alias
explorer.exe "::{7007ACC7-3202-11D1-AAD2-00805FC1270E}"
powershell
function jc-open-network(){
    & C:\Windows\explorer.exe ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
}