Coder Social home page Coder Social logo

scoop-better-shimexe's Introduction

shim.c

shim.c is a simple Windows program that, when started:

  1. Looks for a file with the exact same name as the running program, but with the extension shim (e.g. C:\bin\foo.exe will read the file C:\bin\foo.shim).
  2. Reads and parses the files into a Scoop shim format.
  3. Executes the target executable with the given arguments.

shim.c was originally made to replace Scoop's shim.cs since it had several important flaws:

  1. It was made in C#, and thus required an instantiation of a .NET command line app everytime it was started, which can make a command run much slower than if it had been ran directly;
  2. It did not handle Ctrl+C and other signals correctly, which could be quite infuriating (and essentially killing REPLs and long-running apps).

shim.c is:

  • Faster, because it does not use the .NET Framework, and parses the .shim file in a simpler way.
  • More efficient, because by the time the target of the shim is started, all allocated memory will have been freed.
  • And more importantly, it works better:
    • Signals originating from pressing Ctrl+C are ignored, and therefore handled directly by the spawned child. Your processes and REPLs will no longer close when pressing Ctrl+C.
    • Children are automatically killed when the shim process is killed. No more orphaned processes and weird behaviors.

Note: This project is not affiliated with Scoop.

Installation for Scoop

  • In a Visual Studio command prompt, run cl /O1 shim.c.
  • Replace any .exe in scoop\shims by shim.exe.

An additional script, repshims.bat, is provided. It will replace all .exes in the user's Scoop directory by shim.exe.

Example

Given the following shim gs.shim:

path = C:\Program Files\Git\git.exe
args = status -u

In this directory, where gs.exe is the compiled shim.c:

C:\Bin\
   gs.exe
   gs.shim

Then calling gs -s will run the program C:\Program Files\Git\git.exe status -u -s.

Shim format

Shims follow the same format as Scoop's shims: line-separated key = value pairs.

path = C:\Program Files\Git\git.exe
args = status -uno

path is a required value, but args can be omitted. Also, do note that lines must end with a line feed.

License

SPDX-License-Identifier: MIT OR Unlicense

scoop-better-shimexe's People

Contributors

71 avatar couleurm avatar hasufell avatar rasa avatar vieiraa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scoop-better-shimexe's Issues

Crash when handle parameters with shim binary

I notice that Emacs shim which's using this shim.exe crash when running emacsclient -a="" -nw.
It seems that there're memory early release error somewhere, thus leads to access violation.

Side note:
I've convert this to Cpp with better memory management notation (using smart pointer and c++17 features), let me know if you think it's appropriate to be able to merged back here.
https://github.com/kiennq/scoop-better-shimexe

Doesn't detect GUI apps

I fixed this and some other issues in my fork - https://github.com/lymanepp/scoop-better-shimexe

  • Fix check for GUI apps
  • Don't wait for GUI apps to complete
  • Building with /MD option (msvcrt.dll) makes for much smaller shim.exe (12 KB vs 113 KB)

FYI, I did some refactoring and cleanup alongside those fixes. Here's a PR #17 if you're interested.

Scoop branding is unnecessary

I found this project by looking for something like what Chocolatey does with its shims without having to use Chocolatey's PowerShell modules. I don't use Scoop at all. This works much more reliably than alternatives like doskey aliases or batch files.

Furthermore it'd be good to describe how to create a .shim file for those who have never used Scoop before. (Honestly this would be good to include either way, but especially if you would be interested in removing the Scoop association.)

Forward arguments

I understand that you can place arguments in the .shim file and have the target exe launch with those arguments. But how do you have the shim.exe forward the arguments passed to it to the target exe?

If not currently possible can that be the default if an args isn't specified in the .shim file?

Add licence

Hi #71 (loving that username),

I found your project via the Scoop project, here and found it really useful in a separate but related project to create executables of Python "console_scripts" that has relative paths to the Python interpreter here, as opposed to the absolute ones it creates per default.

I would like to ask if you could attach a permissive licence, such as MIT or better yet The Unlicence to your project such that I could bundle it alongside mine?

Support resolving shim's directory in the path and args

In my use case, I want to use this shim.exe to launch a JavaScript application through Node.js, so something like:

path = node.exe
args = ./cli.js

But since it does not support resolving directories relative to the shim's root, I'm not able to use it, because I'll not have control about where NPM will put my cli.js, only that it will be beside the shim.exe.

.shim file has to end with a CRLF

This threw me for a loop when I first tried this project out. It's not mentioned in the documentation that this is required, and I'm not entirely sure why it would be. It doesn't matter if the optional 'args' line is used or not.

Does not detect that the shim points to a GUI app

Because it does not detect that it had started a gui app say PuTTY in my case ScoopInstaller/Extras#2801 (comment) it leaves the window open and if you close the window it also closes the process.

Not sure if it will help but say you get the HANDLE from your CreateProcess perhaps use this method to see if the process is going to use GUI resources to detect if it is going to be a Windowed app or not https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getguiresources

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.