Skip to content

Command-line tool to enable switchable graphics for certain commands

License

Notifications You must be signed in to change notification settings

tqdv/App-Switchable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published