From facb4708e2735f138e33dd518a390e091a9dab61 Mon Sep 17 00:00:00 2001 From: jonnybravo Date: Mon, 5 Jan 2026 15:48:01 +0100 Subject: [PATCH] added tmux and all --- roles/all/meta/main.yml | 3 ++ roles/tmux/tasks/main.yml | 39 +++++++++++++++++++ roles/tmux/tasks/tmux_config.yml | 63 +++++++++++++++++++++++++++++++ roles/tmux/templates/tmux.conf.j2 | 27 +++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 roles/all/meta/main.yml create mode 100644 roles/tmux/tasks/main.yml create mode 100644 roles/tmux/tasks/tmux_config.yml create mode 100644 roles/tmux/templates/tmux.conf.j2 diff --git a/roles/all/meta/main.yml b/roles/all/meta/main.yml new file mode 100644 index 0000000..0e0c47e --- /dev/null +++ b/roles/all/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - role: local.fish_shell.tmux + - role: local.fish_shell.fish diff --git a/roles/tmux/tasks/main.yml b/roles/tmux/tasks/main.yml new file mode 100644 index 0000000..f8d2073 --- /dev/null +++ b/roles/tmux/tasks/main.yml @@ -0,0 +1,39 @@ +--- +- name: Install tmux + package: + name: "{{ item }}" + state: present + loop: + - "tmux" + - "git" + +- name: Get all users from /etc/passwd + ansible.builtin.getent: + database: passwd + register: all_users + +- name: Create a list of home directories for bash and zsh users + set_fact: + user_home_dirs: "{{ user_home_dirs | default([]) + [item.value[4]] }}" + loop: "{{ all_users.ansible_facts.getent_passwd | dict2items }}" + when: item.value[5] in ['/bin/bash', '/bin/zsh', '/usr/bin/bash', '/usr/bin/zsh', '/usr/bin/fish'] + +- name: Display the list of collected home directories + ansible.builtin.debug: + var: user_home_dirs + +- name: Tmux config Play + include_tasks: tmux_config.yml + loop: "{{ user_home_dirs }}" + +# ======================================================================== +# EXAMPLE: Here is how you can reuse the 'user_home_dirs' list +# This example task iterates through the list of home directories +# and creates a file named 'test.txt' in each directory. +# ======================================================================== +# - name: Example - Create a file in each home directory +# ansible.builtin.file: +# path: "{{ item }}/test.txt" +# state: touch +# mode: '0644' +# loop: "{{ user_home_dirs }}" diff --git a/roles/tmux/tasks/tmux_config.yml b/roles/tmux/tasks/tmux_config.yml new file mode 100644 index 0000000..7d6c4dd --- /dev/null +++ b/roles/tmux/tasks/tmux_config.yml @@ -0,0 +1,63 @@ +--- +- name: Define user and home directory variables + ansible.builtin.set_fact: + config_owner: "{{ item | basename }}" + home_dir: "{{ item }}" + +- name: Define plugins to install + ansible.builtin.set_fact: + tmux_plugins: + - { name: 'catppuccin', repo: 'https://github.com/catppuccin/tmux.git', path: 'plugin/catppuccin', version: 'v2.1.0' } + - { name: 'tmux-cpu', repo: 'https://github.com/tmux-plugins/tmux-cpu.git', path: 'plugins/tmux-plugins/tmux-cpu', version: 'master' } + - { name: 'tmux-battery', repo: 'https://github.com/tmux-plugins/tmux-battery.git', path: 'plugins/tmux-plugins/tmux-battery', version: 'master' } + +- name: "Create plugin directories" + ansible.builtin.file: + path: "{{ home_dir }}/.config/tmux/{{ plugin_item.path }}" + state: directory + owner: "{{ config_owner }}" + group: "{{ config_owner }}" + mode: '0755' + loop: "{{ tmux_plugins }}" + loop_control: + loop_var: plugin_item + +- name: "Add git safe.directories" + ansible.builtin.command: "git config --global --add safe.directory {{ home_dir }}/.config/tmux/{{ plugin_item.path }}" + changed_when: false + loop: "{{ tmux_plugins }}" + loop_control: + loop_var: plugin_item + +- name: "Clone plugins" + ansible.builtin.git: + repo: "{{ plugin_item.repo }}" + dest: "{{ home_dir }}/.config/tmux/{{ plugin_item.path }}" + version: "{{ plugin_item.version }}" + loop: "{{ tmux_plugins }}" + loop_control: + loop_var: plugin_item + +- name: "Set plugin ownership" + ansible.builtin.file: + path: "{{ home_dir }}/.config/tmux/{{ plugin_item.path }}" + state: directory + owner: "{{ config_owner }}" + group: "{{ config_owner }}" + recurse: yes + loop: "{{ tmux_plugins }}" + loop_control: + loop_var: plugin_item + +- name: Set catppuccin_install_path for template + ansible.builtin.set_fact: + catppuccin_install_path: "{{ home_dir }}/.config/tmux/{{ (tmux_plugins | selectattr('name', 'equalto', 'catppuccin') | first).path }}" + +- name: Install Template + ansible.builtin.template: + src: "tmux.conf.j2" + dest: "{{ home_dir }}/.tmux.conf" + owner: "{{ config_owner }}" + group: "{{ config_owner }}" + mode: '0644' + diff --git a/roles/tmux/templates/tmux.conf.j2 b/roles/tmux/templates/tmux.conf.j2 new file mode 100644 index 0000000..9f2782d --- /dev/null +++ b/roles/tmux/templates/tmux.conf.j2 @@ -0,0 +1,27 @@ +# ~/.tmux.conf + +# Options to make tmux more pleasant +set -g mouse on +set -g default-terminal "tmux-256color" + +# Configure the catppuccin plugin +set -g @catppuccin_flavor "mocha" # latte, frappe, macchiato, or mocha +set -g @catppuccin_window_status_style "rounded" # basic, rounded, slanted, custom, or none + +# Load catppuccin +run {{ catppuccin_install_path }}/catppuccin.tmux +# For TPM, instead use `run ~/.config/tmux/plugins/tmux/catppuccin.tmux` + +# Make the status line pretty and add some modules +set -g status-right-length 100 +set -g status-left-length 100 +set -g status-left "" +set -g status-right "#{E:@catppuccin_status_application}" +set -agF status-right "#{E:@catppuccin_status_cpu}" +set -ag status-right "#{E:@catppuccin_status_session}" +set -ag status-right "#{E:@catppuccin_status_uptime}" +set -agF status-right "#{E:@catppuccin_status_battery}" + +run ~/.config/tmux/plugins/tmux-plugins/tmux-cpu/cpu.tmux +run ~/.config/tmux/plugins/tmux-plugins/tmux-battery/battery.tmux +# Or, if using TPM, just run TPM