Skip to content

Commit

Permalink
feat: add yaml config support (#13)
Browse files Browse the repository at this point in the history
* Added other text editors and utilities

* Add extra options

* Added package managers

* Fix tabs in code

* Add fzf and skim

* Init of custom icons branch

* Added recommended icons

* Add Nix

* Update README

* Add screenshot

* Init for yaml branch

* feat: set default configs

* feat: get user config to work

* docs: update docs

* chore: delete unused conf file

---------

Co-authored-by: Kenos <[email protected]>
  • Loading branch information
joshmedeski and kenos1 authored Aug 16, 2023
1 parent 60d4feb commit f0bfaff
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 121 deletions.
63 changes: 20 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,41 @@
<a href="https://www.joshmedeski.com/posts/tmux-nerd-font-window-name-plugin/" target="_blank">

![thumbnail](https://github.com/joshmedeski/tmux-nerd-font-window-name/blob/main/tmux-nerd-font-window-name-thumb.jpeg?raw=true)

</a>

# tmux nerd font window name plugin

Automatically rename your tmux windows to Nerd Font Icons.
Automatically add Nerd Font support to your tmux window names!

## Prerequisites
![tmux-nerd-font-window-name screenshot](./tmux-nerd-font-window-name-screenshot.png)

## Requirements

- [tmux](https://github.com/tmux/tmux)
- [tpm](https://github.com/tmux-plugins/tpm)
- [Nerd Font](https://www.nerdfonts.com/)
- [yq](https://github.com/mikefarah/yq)

## How to install
## Installation

### Install tpm plugin

This script can be installed with the [Tmux Plugin Manager (tpm)](https://github.com/tmux-plugins/tpm).

Add the following line to your `~/.tmux.conf` file:

```conf
set -g @plugin 'joshmedeski/tmux-nerd-font-window-name'
```

### Options
This plugin can be installed with the [Tmux Plugin Manager (tpm)](https://github.com/tmux-plugins/tpm).

Add the following options to your `tmux.conf` before you set the plugin.
Add the following line to your tmux configuration file:

```sh
# shows the window name next to the icon (default false)
set -g @tmux-nerd-font-window-name-show-name true
set -g @plugin 'joshmedeski/tmux-nerd-font-window-name'
```

### Minimalist format

If you want a minimalist format and only show the nerd font icon. You can update your window status to just `#W` (window name) in your tmux config.

```conf
set -g window-status-current-format '#[fg=magenta]#W'
set -g window-status-format '#[fg=gray]#W'
```
## Configuration

### Custom shell icon
You can configure this plugin by creating a `~/.config/tmux/tmux-nerd-font-window-name.yml` file. The following options can be changed:

To specify a custom shell icon, use the following option to set any icon you prefer:
```yml
config:
fallback-icon: "?" # icon to use if no definition is found
show-name: true # show the window name with the icon

```sh
set -g @tmux-nerd-font-window-name-shell-icon ""
icons:
zsh: "" # overwrite with your own symbol (Nerd Font icon, emoji, whatever!)
cmatrix: "🤯" # add new entries that aren't included
```
## How it works

When installed, your window names will automatically update to a Nerd Font that matches the activity (ex: vim, bash, node, ect...).

## Tasks

- [x] Create tpm plugin
## Contributing
## Contributions
I encourage contributors! I want to make this plugin the best it can be. Feel free to fork it and submit pull requests with any new ideas or improvements you have.
Contributions are welcome! Feel free to make a pull request to submit more preset icon settings or improve the codebase!
46 changes: 46 additions & 0 deletions bin/defaults.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# cSpell:disable
config:
fallback-icon: "?"
show-name: true

icons:
apt: ""
bash: ""
beam.smp: ""
beam: ""
brew: ""
cfdisk: ""
dnf: ""
docker: ""
dpkg: ""
emacs: ""
fdisk: ""
fish: ""
git: ""
gitui: ""
go: ""
htop: ""
lazydocker: ""
lazygit: ""
lf: ""
lfcd: ""
lvim: ""
nala: ""
node: ""
nvim: ""
pacman: ""
parted: ""
paru: ""
Python: ""
ranger: ""
ruby: ""
rustc: ""
rustup: ""
tcsh: ""
tig: ""
tmux: ""
top: ""
vim: ""
yay: ""
yum: ""
zsh: ""
83 changes: 20 additions & 63 deletions bin/tmux-nerd-font-window-name
Original file line number Diff line number Diff line change
@@ -1,73 +1,30 @@
#!/usr/bin/env bash

NAME=$1
SHOW_NAME="$(tmux show -gqv '@tmux-nerd-font-window-name-show-name')"
NAME="$1"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEFAULT_CONFIG="$CURRENT_DIR/defaults.yml"
USER_CONFIG="$HOME/.config/tmux/tmux-nerd-font-window-name.yml"

function get_shell_icon() {
local default_shell_icon=""
local shell_icon
shell_icon="$(tmux show -gqv '@tmux-nerd-font-window-name-shell-icon')"
if [ "$shell_icon" != "" ]; then
echo "$shell_icon"
else
echo "$default_shell_icon"
get_config_value() {
local key=$1
local value
value="$(yq "$key" "$USER_CONFIG")"
if [ "$value" == "null" ]; then # get default config value
value="$(yq "$key" "$DEFAULT_CONFIG")"
fi
echo "$value"
}

SHELL_ICON=$(get_shell_icon)
ICON="$(get_config_value ".icons.$NAME")"

get_icon() {
case $NAME in
tmux)
echo ""
;;
htop | top)
echo ""
;;
fish | zsh | bash | tcsh)
echo "$SHELL_ICON"
;;
vi | vim | nvim | lvim)
echo ""
;;
lazygit | git | tig)
echo ""
;;
node)
echo ""
;;
ruby)
echo ""
;;
go)
echo ""
;;
lf | lfcd)
echo ""
;;
beam | beam.smp) # Erlang runtime
echo ""
;;
rustc | rustup)
echo ""
;;
Python)
echo ""
;;
*)
if [ "$SHOW_NAME" = true ]; then
echo ""
else
echo "$NAME"
fi
;;
esac
}

ICON=$(get_icon)
if [ "$ICON" == "null" ]; then
FALLBACK_ICON="$(get_config_value '.config.fallback-icon')"
ICON="$FALLBACK_ICON"
fi

SHOW_NAME="$(get_config_value '.config.show-name')"
if [ "$SHOW_NAME" = true ]; then
echo "$ICON" "$NAME"
else
echo "$ICON"
ICON="$ICON $NAME"
fi

echo "$ICON"
15 changes: 0 additions & 15 deletions cspell.json

This file was deleted.

8 changes: 8 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs;[
tmux
yq-go
nodePackages.bash-language-server
];
}
Binary file modified tmux-nerd-font-window-name-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed tmux-nerd-font-window-name-thumb.jpeg
Binary file not shown.

0 comments on commit f0bfaff

Please sign in to comment.