tqdv / App-Switchable

Command-line tool to enable switchable graphics for certain commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

App::Switchable

A command-line tool to enable switchable graphics for certain commands.

You won't need to type DRI_PRIME=1 steam again.

Usage

Write the following to the configuration file ~/.config/switchable/config.json.

{
    "match": [ "steam" ]
}

And then just run a command that matches.

steam

And it will automatically use your discrete GPU.

Requirements

Installation

  • Install bash-preexec to ~/.bash-preexec.sh (the default)
  • Add the executable to your PATH
  • Add eval "$( switchable init )" to your .bashrc

Configuration

We first look at ~/.config/switchable/config.json, and if that doesn't exist, we try ~/.switchable/config.json.

The file is a JSON object with the following format. Note that it does allow comments. See JSON::PP docs for more details about the allowed JSON syntax.

{
    "driver": 1,   // Default value for DRI_PRIME
    "preexec": "/path/to/bash/preexec", // Path to bash-preexec
                                        // if it's not in its default location
    "match": [     // Regexes to match commands against
        "steam",
        "echo"
    ],
    "alias": [     // Commands to alias
        "glxgears"
    ]
}

Caveats

Having switchable being called for each command adds around 140ms to each command you type. However, it isn't run when nothing is typed.

TODO add comparison video.

switchable run doesn't work with aliases such as ll.

Contributing

Project documentation is in docs/, start from the index.

Testing

We mostly test either specific functions in Perl, or the general output of commands (not the behaviour). In short, it's a bit pointless.

Requirements:

Run the following commands to start the tests.

# In the project root
prove -l
bats -t t

See also

License

This software is copyright (c) 2019 by Tilwa Qendov.

This is free software, licensed under the Artistic License 2.0 (GPL Compatible)

About

Command-line tool to enable switchable graphics for certain commands

License:Other


Languages

Language:Perl 81.8%Language:Shell 18.2%