Coder Social home page Coder Social logo

dark-mode's Introduction

Dark Mode

MacOS and Linux scripts to interact with dark mode.

Features

  • Get current mode
  • Change active mode
  • Listen for theme events and run a shell script on change
  • Listen for theme events and change between chriskempson/base16-shell themes

Installation

MacOS

Manual

Either run it directly with

./macos/dark-mode.swift <command>

Or compile it with

swiftc -o dark-mode ./macos/dark-mode.swift

With Zinit

zinit ice lucid from='gh' if='[[ "$(uname -s)" == Darwin* ]]' \
	atclone='swiftc -o dark-mode macos/dark-mode.swift' atpull="%atclone" sbin='dark-mode'
zinit light @AntoinePrv/dark-mode

Linux (Gnome)

Manual

The script is a standalone bash wrapper around gsettings.

./linux/gnome/dark-mode.sh

With Zinit

zinit ice lucid from='gh' if='[[ "$(uname -s)" == Linux* ]]' \
	sbin='linux/gnome/dark-mode.sh -> dark-mode'
zinit light @AntoinePrv/dark-mode

Usage

Usage:
dark-mode (help | --help | -h)
Print this message and exit.

dark-mode get
Print the current mode, either "dark" or "light".

dark-mode dark
Set theme to dark.

dark-mode light
Set theme to light

dark-mode toogle
Toogle the theme to the opposite one.

dark-mode listen <script> [<args>...]
Listen for theme changes and run the given script.
The new theme, either "dark" or "light" is passed as the last argument to the script.

dark-mode base16 --root <base16-root> --light <light-theme> --dark <dark-theme>
Listen for theme changes and change to the base16 theme accordingly

Example using listen to change terminal theme

Using chriskempson/base16-shell to change the terminal theme, one can use something like

dark-mode base16 --root "${HOME}/.local/share/base16" --light "ia-light" --dark "ia-dark"

To run the dark-mode listener in the background, for instance starting it in .bashrc/.zshrc, you can use

# Only run if using MacOS.
if [[ "$OSTYPE" == "darwin"* ]]; then
    # Don't run withing Tmux or SSH, as it will already be running in the first terminal session.
    if [["${TERM}" != "screen"* &&  ! -n "${TMUX}" ]] && ! [[ -n "${SSH_CLIENT}" || -n "${SSH_TTY}" ]]; then
        (
            # Run dark-mode in the background, removing it from the job list.
            dark-mode base16 --root "${XDG_DATA_HOME}/base16" --light "one-light" --dark "onedark" &
            # Kill dark-mode when the shell exits.
            bash -c "while ps -p $$ 2>&1 1>/dev/null; do sleep 60; done; pkill -P $!" &
        )
    fi
fi

Credit

Heavily inspired by:

dark-mode's People

Contributors

antoineprv avatar

Watchers

 avatar  avatar  avatar

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.