Skip to content

Commit

Permalink
i did what I wanted for myself - vim shim for WT (and it works!)
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Sep 20, 2021
1 parent c76637a commit 68fd96b
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 64 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2021 Ivan Gavryliuk

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
48 changes: 34 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,65 @@
# win-shim

**<span style="color: red">THIS IS AN EARLY ALPHA!</span>**
> THIS IS AN EARLY ALPHA!
Lightweight and customisable shim executable for **Windows**. Shims supposed to work just like target executables they are shadowing.

It's written in safe C++20.
Lightweight and customisable shim executable for **Windows** written in safe modern `C++ 20`.

## Features

- Lightweight and Fast. Does not add to startup time, even for tiny utilities.
- Self-sufficient and clean. Does not read config files or write anywhere. Does not need or require any external runtimes.
- Mirrors:
- [ ] Executable name.
- [ ] Icon.
- [ ] Version information.
- [ ] Exit status (error code).
- Extras
- [x] Exit status (error code).
- [x] Original version information.
- [x] Original file details.
- [x] Original application icon.
- [ ] Application manifest.
- Supports:
- [x] Any command line, parametrised.
- Extras (on the roadmap)
- [ ] Limit registry access.
- [ ] Limit filesystem access.
- [ ] Limit amount of available RAM.
- [ ] Change clock.
- [ ] Freeze in background.

## How to Use

Download the latest release when ready.
Download the latest release when ready (still in dev!).

Originally this shim was written because I wanted to associate a file extension in Windows with [vim](https://www.vim.org/), but opened as a tab in [windows terminal](https://github.com/microsoft/terminal) instead of an ugly terminal popup window. WT [does allow it](https://docs.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows), however I would need to build a command line like:

```bash
wt -w 0 nt vim.exe <path_to_file>
```

Unfortunately, you cannot associate a command line with an extension in Windows, only executable with an extension, so I though I'd build a shim executable for this.

In order to achieve this, run `shmake` like following:

```bash
shmake.exe -c "wt -w 0 nt vim.exe %s" -o vimwt.exe -m "c:\scoop\apps\vim\3.2\vim.exe"
```

which should generate a new executable `winwt.exe` that when called with an argument will open a tab in WT! `%s` is replaced by arguments passed to `wimwt.exe` when it executes. The last argument `-m` will also mirror vim application icon, version info and description so it looks just like vim everywhere.


## Building

As this is **Windows exclusive**, you need Visual Studio 2019 with Windows SDK installed. Normally I would use CMake, but is considerably harder (not impossible) to use when you need access to OS specific tools, especially native resources (which I utilise heavily to do the magic).
As this is **Windows Exclusive**, you need Visual Studio 2019+ with Windows SDK installed. Normally I would use CMake, but it is considerably harder (not impossible) when you need access to OS specific tools, especially native resources (which I utilise heavily to do the magic). It is also very well integrated with `vcpkg`.

`shmake` (but not shim) has dependency on:
- `boost::program_options`.
- `boost::program_options` to present you with a nice command line.
- todo...

All the dependencies are installed via [vcpkg](https://github.com/microsoft/vcpkg).

```
vcpkg install boost-program-options:x64-windows boost-program-options:x64-windows-static
```

`shim` does not have any dependencies and is kept as small and light as possible.
`shim` **does not have any dependencies** and is kept as small and light as possible.

### Extra Oddness

`shmake` embeds `shim` inside it as a Windows native resource, so it's completely self-sufficient and can be distributed as a single `exe`. To do that, `smake`'s pre-build step copies `shim.exe` to `shim.bin` before build (as a pre-build step). Apparently `shim` is set as a project dependency of `shmake`, so it generates a full usable binary.
`shmake` embeds `shim` inside it as a Windows native resource, so it's completely self-sufficient and can be distributed as a single `.exe`. To do that, `shmake`'s pre-build step copies `shim.exe` to `shim.bin` before build (as a pre-build step). Apparently `shim` is set as a project dependency of `shmake`, so it generates a full usable binary.
Binary file modified shim/icon.ico
Binary file not shown.
Binary file modified shim/shim.aps
Binary file not shown.
3 changes: 2 additions & 1 deletion shim/shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ int wmain(int argc, wchar_t* argv[])

wcout << L"waiting... ";
::WaitForSingleObject(pi.hProcess, INFINITE);
wcout << L"done." << endl;

DWORD exit_code = 0;
// if next line fails, code is still 0
::GetExitCodeProcess(pi.hProcess, &exit_code);
wcout << L"done (code: " << exit_code << L")" << endl;


// free OS resources
::CloseHandle(pi.hProcess);
Expand Down
86 changes: 48 additions & 38 deletions shim/shim.rc
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,20 @@ END


/////////////////////////////////////////////////////////////////////////////
// English (United Kingdom) resources
// Neutral (Default) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUD)
LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT
#pragma code_page(1252)

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END

3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -86,24 +60,60 @@ VS_VERSION_INFO VERSIONINFO
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BLOCK "040004b0"
BEGIN
VALUE "CompanyName", "TODO: <Company name>"
VALUE "FileDescription", "TODO: <File description>"
VALUE "FileVersion", "1.0.0.1"
VALUE "CompanyName", "Ivan G"
VALUE "FileDescription", "Shim executable"
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "shim.exe"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "shim.exe"
VALUE "ProductName", "TODO: <Product name>"
VALUE "ProductVersion", "1.0.0.1"
VALUE "ProductName", "Shim executable"
VALUE "ProductVersion", "1.0.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
VALUE "Translation", 0x400, 1200
END
END

#endif // Neutral (Default) resources
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////
// English (United Kingdom) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#pragma code_page(1252)

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END

3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
Expand Down
Binary file modified shmake/data.aps
Binary file not shown.
39 changes: 39 additions & 0 deletions shmake/data.rc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,45 @@ END

IDR_SHIM_EXE RCDATA "shim.bin"


/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "CompanyName", "Ivan G"
VALUE "FileDescription", "Shim maker"
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "shmake.exe"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "shmake.exe"
VALUE "ProductName", "Shim maker"
VALUE "ProductVersion", "1.0.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END

#endif // English (United Kingdom) resources
/////////////////////////////////////////////////////////////////////////////

Expand Down
Loading

0 comments on commit 68fd96b

Please sign in to comment.