{"id":18827106,"url":"https://github.com/nullpo-head/source-win-bat","last_synced_at":"2025-04-14T02:08:50.570Z","repository":{"id":56896511,"uuid":"160064155","full_name":"nullpo-head/source-win-bat","owner":"nullpo-head","description":"A utility to run Windows Batch files in WSL / Cygwin / MSYS2 and sync the environment variables, doskeys, and working directories.","archived":false,"fork":false,"pushed_at":"2020-01-06T16:40:03.000Z","size":80,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T02:08:45.315Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nullpo-head.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-02T15:58:44.000Z","updated_at":"2024-01-27T14:08:28.000Z","dependencies_parsed_at":"2022-08-20T17:10:29.653Z","dependency_job_id":null,"html_url":"https://github.com/nullpo-head/source-win-bat","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullpo-head%2Fsource-win-bat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullpo-head%2Fsource-win-bat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullpo-head%2Fsource-win-bat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullpo-head%2Fsource-win-bat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nullpo-head","download_url":"https://codeload.github.com/nullpo-head/source-win-bat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809044,"owners_count":21164896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T01:12:59.768Z","updated_at":"2025-04-14T02:08:50.552Z","avatar_url":"https://github.com/nullpo-head.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SourceWinBat - Source a Windows Batch in Bash!\n\n`sw`, or SourceWinBat is a CLI utility to run Windows batch files in WSL/MSYS2/Cygwin,\nand sync the shell environments of Bash and the Windows command line, including\n* Environment variables\n* Doskeys\n* Working directories\n\n## Why? What is that useful for?\n\nSourceWinBat lets you run Windows initialization scripts in Bash, as if you run `source` \ncommand for Bash scripts.  \nThat enables you to do your daily Windows jobs that require initialization batch scripts in your favorite UNIX-compatible environments!\n\n\n## Usage\n\nAfter initalization, `sw` function is defined in your Bash environment. \nRun your Windows batch files or Windows CLI commands by `sw`.\n\nYou can run a Windows batch file\n```console\n$ cat winbat.bat\n@echo off\nset ENV1=bar!  ; Environment variables will be synced\necho foo!      ; Execute Windows echo commands\nver            ; Execute Windows ver command, which outputs the OS version\n$ sw winbat.bat  # winbat.bat is executed\nfoo!\n\nMicrosoft Windows [Version 10.0.17763.195]\n$ echo $ENV1     # ENV1 is synced!\nbar!\n```\n\nYou can also run a Windows command directly.\n```console\n$ sw ver\n\nMicrosoft Windows [Version 10.0.17763.195]\n```\n\n## Examples\n\n### Environment Syncing\n\nSourceWinBat syncs environment variables, doskeys, and working directories of the\nBash environment with those of the Windows cmd environment where a batch file is executed.\n\n#### 1. Environment variables\nA batch file can see the exported environment variables of Bash.  \nConversely, Bash has the environment variables defined by the batch file and Windows system\nafter the batch file is executed. `PATH` is properly converted.\n\n```console\n$ export UNIXENV=\"An UNIX environment variable is imported!\"\n$ cat syncenv.bat\necho %UNIXENV%\nset WINENV=A Windows environment variable is imported!\nset PATH=C:\\any\\path;%PATH%\n$ sw syncenv.bat  # syncenv sees the value of $UNIXENV, which we defined in Bash!\nAn UNIX environment variable is imported!\n$ echo $WINENV    # Now we can see $WINENV, which is set in synenv.bat!!\nA Windows environment variable is imported!\n$ echo $PATH      # PATH is converted to the path of WSL\n/mnt/c/any/path:/usr/bin/:/bin:(other paths go on...)\n```\n\n#### 2. Doskeys\nSourceWinBat enables Bash to import doskeys from Windows Batch files as Bash functions.\n\n```console\n$ cat syncdoskey.bat\ndoskey echo1stparam=echo $1\ndoskey echoallparams=echo $*\ndoskey verver=ver\n$ sw syncdoskey.bat\n$ echo1stparam 1st 2nd 3rd  # echo1stparam is imported!\n1st\n$ echo1stparam %OS%         # \"echo $1\" is executed by cmd.exe, so %OS% is expanded\nWindows_NT\n$ echoallparams 1st 2nd 3rd\n1st 2nd 3rd\n$ verver\n\nMicrosoft Windows [Version 10.0.17763.195]\n```\n\n#### 3. Working directories\nAs `source` of built-in Bash command syncs working directories, SourceWinBat also syncs them.\n\n```console\n$ cd ~\n$ cat syncwd.bat\npushd C:\\Windows\npushd C:\\Windows\\system32\ncd C:\\Windows\\system32\\drivers\n$ sw syncwd.bat\n$ pwd   # The current directory of Bash is changed\n/mnt/c/Windows/System32/drivers\n$ dirs  # The directory stack is synced with that of the batch file\n/mnt/c/Windows/System32/ /mnt/c/Windows /home/nullpo\n```\n\n## Installation\n\nSourceWinBat is written in Ruby. You can install it by Gem.\n```console\n# gem install source_win_bat\n```\n\nExecute the line below to add the initialization in your `.bashrc`.\n```console\n$ echo 'eval \"$(init_sw)\"' \u003e\u003e ~/.bashrc\n```\nAfter restarting Bash, you will be able to use `sw` in your shell.  \nCurrently, SourceWinBat supports only Bash as a shell.\n\n## Requirements\n\n### 1. For WSL users\n\nOctober update or later is required. SourceWinBat requires ConPTY API.\n\n### 2. For MSYS2 and Cygwin users\n\nIf you use MSYS2 and Cygwin with SourceWinBat, `winpty` command is required.\nClone it from its GitHub repository and build it from the source. The repository is https://github.com/rprichard/winpty .  \nFor MSYS2 users, DO NOT install `winpty` via `pacman`. As of 2019/01/03, Pacman installs the latest released version, 0.4.3-1, but this version does not work anymore.\n\n## TODOs\n\n* Support non-ascii characters in Cygwin and MSYS2. SourceWinBat already supports them in WSL.\n* Support shell operators in doskey such as pipe.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnullpo-head%2Fsource-win-bat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnullpo-head%2Fsource-win-bat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnullpo-head%2Fsource-win-bat/lists"}