├── LICENSE ├── README.md ├── example.toml └── script.sh /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `pywal2alacritty` 2 | 3 | > 🎨 A shell script to get colors from [Pywal](https://github.com/dylanaraps/pywal) and apply to [Alacritty](https://alacritty.org/config-alacritty.html) TOML config with regular expressions. 4 | 5 | ## 🤔 Why? 6 | Currently, there's no easy way to send [wal](https://github.com/dylanaraps/pywal/) colors to Alacritty config in macOS. So I wrote this script to auto-update colors as a workaround. 7 | 8 | ## 🔽 Setup 9 | **Dependencies:** `grep`, `sed` 10 | 11 | Go to [raw file](https://github.com/egeesin/alacritty-color-export/raw/master/script.sh) and save to your script directory ($PATH) or open your terminal emulator: 12 | 13 | **Note:** If you're behind Alacritty [13.0.0](https://alacritty.org/changelog_0_13_0.html), get the script from v0.1.1 release in [Tags](https://github.com/egeesin/pywal2alacritty/tags) list in order to import colors to . 14 | 15 | ```sh 16 | git clone https://github.com/egeesin/alacritty-color-export 17 | cd alacritty-color-export 18 | chmod +x script.sh 19 | ``` 20 | 21 | ## 🎛️ Usage 22 | Before executing the script, comment existing color declarations out in order to avoid duplication errors and keep your initial colors (No need if you have your colors imported somewhere else). 23 | Also make sure you run ``wal -i `` (or ``wal -ni `` if you're on macOS) at least once to have the colors ready in your Wal cache folder so the script can convert it. 24 | 25 | ```sh 26 | # Run the script 27 | ./path/to/script.sh 28 | 29 | # Run the script with custom config path 30 | ./path/to/script.sh 31 | ``` 32 | 33 | ## 🚧 Example 34 | 35 | **1. Terminal Emulator** 36 | ```sh 37 | $ ./path/to/script.sh 38 | ``` 39 | 40 | **2. Input (`~/.cache/wal/colors.sh`):** 41 | ```sh 42 | ... 43 | # Special 44 | background='#180f18' 45 | foreground='#cbc2e1' 46 | cursor='#cbc2e1' 47 | 48 | # Colors 49 | color0='#180f18' 50 | color1='#6A538E' 51 | color2='#464AAB' 52 | color3='#916A98' 53 | color4='#C569B5' 54 | color5='#EBB0B2' 55 | color6='#AD93D5' 56 | color7='#cbc2e1' 57 | color8='#8e879d' 58 | color9='#6A538E' 59 | color10='#464AAB' 60 | color11='#916A98' 61 | color12='#C569B5' 62 | color13='#EBB0B2' 63 | color14='#AD93D5' 64 | color15='#cbc2e1' 65 | ... 66 | ``` 67 | 68 | **3. Output (Default Alacritty config path: `~/.config/alacritty/alacritty.toml`):** 69 | ```toml 70 | ... 71 | 72 | [window.padding] 73 | x = 12 74 | y = 22 75 | 76 | # BEGIN ACE 77 | [colors.primary] 78 | background = '#180f18' 79 | foreground = '#cbc2e1' 80 | 81 | [colors.cursor] 82 | text = '#180f18' # Apply background color to color of text inside cursor 83 | cursor = '#cbc2e1' # Apply foreground color to color of cursor 84 | 85 | [colors.vi_mode_cursor] 86 | text = '#180f18' # Same as above 87 | cursor = '#cbc2e1' 88 | 89 | [colors.search.matches] 90 | foreground = '#180f18' # Same as above 91 | background = '#cbc2e1' # Apply bright/white color to bg color of matching search 92 | 93 | [colors.search.focused_match] 94 | foreground = 'CellBackground' 95 | background = 'CellForeground' 96 | 97 | [colors.line_indicator] 98 | foreground = 'None' 99 | background = 'None' 100 | 101 | [colors.footer_bar] 102 | foreground = '#8e879d' 103 | background = '#cbc2e1' 104 | 105 | [colors.selection] 106 | text = 'CellBackground' 107 | background = 'CellForeground' 108 | 109 | [colors.normal] 110 | black = '#180f18' 111 | red = '#6A538E' 112 | green = '#464AAB' 113 | yellow = '#916A98' 114 | blue = '#C569B5' 115 | magenta = '#EBB0B2' 116 | cyan = '#AD93D5' 117 | white = '#cbc2e1' 118 | 119 | [colors.bright] 120 | black = '#8e879d' 121 | red = '#6A538E' 122 | green = '#464AAB' 123 | yellow = '#916A98' 124 | blue = '#C569B5' 125 | magenta = '#EBB0B2' 126 | cyan = '#AD93D5' 127 | white = '#cbc2e1' 128 | # END ACE 129 | ``` 130 | **Note:** If you'd like to have different colors for cursor, search matches/focuses from Vi-mode of Alacritty, edit the `script.sh` based on variables like $color1, $color2 etc. 131 | 132 | ## 🔗 Related Links 133 | - [pywal Issue #37 - Alacritty doesn't seem to be working with wal](https://github.com/dylanaraps/pywal/issues/37) 134 | 135 | ## 🤝 Contribution 136 | Don't forget to backup config and thank you for your contribution in advance. Any information from testing on different systems would valuable to anyone who interested in this script. Issues and PR's are welcomed. 137 | 138 | ## 🤷 License 139 | This software is under [The Do What The Fuck You Want To Public License (WTFPL)](http://www.wtfpl.net/about/). 140 | -------------------------------------------------------------------------------- /example.toml: -------------------------------------------------------------------------------- 1 | # vim = set ft=toml: 2 | # Default colors 3 | # [colors.primary] 4 | # background = '0x151718' 5 | # foreground = '0xd6d6d6' 6 | 7 | # Colors the cursor will use if `custom_cursor_colors` is true 8 | # [colors.cursor] 9 | # text = '0x151718' 10 | # cursor = '0xd6d6d6' 11 | 12 | # Normal colors 13 | # [colors.normal] 14 | # black = '0x151718' 15 | # red = '0xcd3f45' 16 | # green = '0x9fca56' 17 | # yellow = '0xe6cd69' 18 | # blue = '0x55b5db' 19 | # magenta = '0xa074c4' 20 | # cyan = '0x55dbbe' 21 | # white = '0xd6d6d6' 22 | 23 | # Bright colors 24 | # [colors.bright] 25 | # black = '0x41535b' 26 | # red = '0xcd3f45' 27 | # green = '0x9fca56' 28 | # yellow = '0xe6cd69' 29 | # blue = '0x55b5db' 30 | # magenta = '0xa074c4' 31 | # cyan = '0x55dbbe' 32 | # white = '0xffffff' 33 | 34 | # colors.indexed_colors = [ 35 | # { index = 16, color = '0xdb7b55' }, 36 | # { index = 17, color = '0x8a553f' }, 37 | # { index = 19, color = '0x282a2b' }, 38 | # { index = 19, color = '0x3b758c' }, 39 | # { index = 20, color = '0x43a5d5' }, 40 | # { index = 21, color = '0xeeeeee' } 41 | # ] 42 | 43 | # BEGIN WAL 44 | [colors.primary] 45 | background = '0x0e0400' 46 | foreground = '0xf5e6c6' 47 | 48 | [colors.cursor] 49 | text = '0x0e0400' 50 | cursor = '0xf5e6c6' 51 | 52 | [colors.vi_mode_cursor] 53 | text = '0x0e0400' 54 | cursor = '0xf5e6c6' 55 | 56 | [colors.search.matches] 57 | foreground = '0x0e0400' # normal/black - color0 58 | background = '0xf5e6c6' # bright/white - color15 59 | 60 | [colors.search.focused_match] 61 | foreground = 'CellBackground' 62 | background = 'CellForeground' 63 | 64 | [colors.line_indicator] 65 | foreground = 'None' 66 | background = 'None' 67 | 68 | [colors.footer_bar] 69 | foreground = '0xaba18a' # bright/black - color8 70 | background = '0xf5e6c6' # normal/white - color7 71 | 72 | [colors.selection] 73 | text = 'CellBackground' 74 | background = 'CellForeground' 75 | 76 | [colors.normal] 77 | black = '0x0e0400' 78 | red = '0xBB6E37' 79 | green = '0xAE8F38' 80 | yellow = '0xC3913F' 81 | blue = '0xDBAA4B' 82 | magenta = '0xF7C95E' 83 | cyan = '0xE3BB87' 84 | white = '0xf5e6c6' 85 | 86 | [colors.bright] 87 | black = '0xaba18a' 88 | red = '0xBB6E37' 89 | green = '0xAE8F38' 90 | yellow = '0xC3913F' 91 | blue = '0xDBAA4B' 92 | magenta = '0xF7C95E' 93 | cyan = '0xE3BB87' 94 | white = '0xf5e6c6' 95 | # END WAL 96 | -------------------------------------------------------------------------------- /script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # pywal2alacritty - get colors from Pywal and apply to Alacritty config 3 | # v0.2.0 4 | # github.com/egeesin 5 | # 6 | # Deps: grep, sed 7 | # Usage: ./script.sh 8 | # ./script.sh 9 | 10 | # Function to display error and quit 11 | die() { 12 | printf "ERR: %s\n" "$1" >&2 13 | exit 1 14 | } 15 | 16 | DEFAULT_MACOS_CONFIG="$HOME"/.config/alacritty/alacritty.toml 17 | 18 | # Wal generates a shell script that defines color0..color15 19 | SRC="$HOME"/.cache/wal/colors.sh 20 | 21 | [ -e "$SRC" ] || die "Wal colors not found, exiting script. Have you executed Wal before?" 22 | printf "Colors found, source ready.\n" 23 | 24 | READLINK=$( command -v greadlink || command -v readlink ) 25 | 26 | # Get config file 27 | if [ -n "$1" ]; then 28 | [ -e "$1" ] || die "Selected config doesn't exist, exiting script." 29 | printf "Config found, destination ready.\n" 30 | CFG=$1 31 | [ -L "$1" ] && { 32 | printf "Following symlink to config...\n" 33 | CFG=$($READLINK -f "$1") 34 | } 35 | else 36 | # Default config path in Mac systems 37 | [ -e "$DEFAULT_MACOS_CONFIG" ] || die "Alacritty config not found, exiting script." 38 | 39 | CFG="$DEFAULT_MACOS_CONFIG" 40 | [ -L "$DEFAULT_MACOS_CONFIG" ] && { 41 | printf "Following symlink to config...\n" 42 | CFG=$($READLINK -f "$DEFAULT_MACOS_CONFIG") 43 | } 44 | fi 45 | 46 | # Get hex colors from Wal cache 47 | # No need for shellcheck to check this, it comes from pywal 48 | # shellcheck disable=SC1090 49 | . "$SRC" 50 | 51 | # Create temp file for sed results 52 | tempfile=$(mktemp) 53 | trap 'rm $tempfile' INT TERM EXIT 54 | 55 | # Delete existing color declarations generated by this script 56 | # If begin comment exists 57 | if grep -q '^# BEGIN WAL' "$CFG"; then 58 | # And if end comment exists 59 | if grep -q '^# END WAL' "$CFG"; then 60 | # Delete contents of the block 61 | printf "Existing generated colors found, replacing new colors...\n" 62 | sed '/^# BEGIN WAL/,/^# END WAL/ { 63 | /^# BEGIN WAL/! { /^# END WAL/!d; } 64 | }' "$CFG" > "$tempfile" \ 65 | && cat "$tempfile" > "$CFG" 66 | # If no end comment, don't do anything 67 | else 68 | die "No '# END WAL' comment found, please ensure it is present." 69 | fi 70 | # If no begin comment found 71 | else 72 | # Don't do anything and notify user if there's an end comment in the file 73 | ! grep -q '^# END WAL' "$CFG" || die "Found '# END WAL' comment, but no '# BEGIN WAL' comment found. Please ensure it is present." 74 | printf "There's no existing 'generated' colors, adding comments...\n"; 75 | printf '# BEGIN WAL\n# END WAL' >> "$CFG"; 76 | fi 77 | 78 | # Write new color definitions 79 | # We know $colorX is unset, we set it by sourcing above 80 | # shellcheck disable=SC2154 81 | { sed "/^# BEGIN WAL/ r /dev/stdin" "$CFG" > "$tempfile" < "$CFG" \ 135 | && rm "$tempfile" 136 | trap - INT TERM EXIT 137 | printf "'%s' exported to '%s'\n" "$SRC" "$CFG" 138 | --------------------------------------------------------------------------------