Skip to content

Instantly share code, notes, and snippets.

@christian-weiss
Created March 1, 2020 13:52
Show Gist options
  • Save christian-weiss/34c3f8f0e27ab26c0138f5b1e286b2b1 to your computer and use it in GitHub Desktop.
Save christian-weiss/34c3f8f0e27ab26c0138f5b1e286b2b1 to your computer and use it in GitHub Desktop.
@echo off
rem This wrapper will log to the root of your password store: <root>/pass_wsl_wrapper.log
echo ### >> pass_wsl_wrapper.log
echo Path to wrapper script: %0 >> pass_wsl_wrapper.log
echo Passed parameters to pass %* >> pass_wsl_wrapper.log
echo Working dir (password store dir of your qtpass profile): %cd% >> pass_wsl_wrapper.log
echo env BASH_CUSTOM_PATH: %BASH_CUSTOM_PATH% >> pass_wsl_wrapper.log
IF DEFINED BASH_CUSTOM_PATH (
set bash_path=%BASH_CUSTOM_PATH%
) else (
echo BASH default path is: C:\Windows\System32\bash.exe >> pass_wsl_wrapper.log
echo BASH used is: %APPDATA%\WSL\bash.exe >> pass_wsl_wrapper.log
set bash_path=%APPDATA%\WSL\bash.exe
)
echo BASH_PATH: %bash_path% >> pass_wsl_wrapper.log
rem Drive letter:
set drive=%CD:~0,1%
rem Path without drive letter:
set subpath=%CD:~3,5000%
rem Path separator converted from windows to linux:
set subpath=%subpath:\=/%
rem Path within WSL:
set pathpasswordstore=/mnt/%drive%/%subpath%
rem We execute unix pass (shell script) in a git bash and pass command line options to that script.
rem To let pass operate in the correct password store dir, we set the environment variable PASSWORD_STORE_DIR to the desired directory.
IF EXIST %bash_path% (
rem Execute the qtpass command:
%bash_path% -c "export PASSWORD_STORE_DIR=%pathpasswordstore%; timeout --preserve-status 15s pass %*;"
) ELSE (
echo "BASH not found. Please enable WSL (Windows-subsystem for Linux) and install Ubuntu from Microsoft Store. If BASH was installed to a custom dir then please set its path as value to environment variable BASH_CUSTOM_PATH and restart QtPass. If BASH was blocked by your personal firewall add an exception rule. Details https://docs.microsoft.com/de-de/windows/wsl/install-win10"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment