From 45b10ea8b49832fc5cbbd0b80b44bbadec72a1a5 Mon Sep 17 00:00:00 2001 From: gemini Date: Fri, 13 Mar 2026 11:57:36 +0100 Subject: [PATCH] feat: Add playbook to organize home directory --- playbooks/organize_home.yml | 130 ++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 playbooks/organize_home.yml diff --git a/playbooks/organize_home.yml b/playbooks/organize_home.yml new file mode 100644 index 0000000..b77ec39 --- /dev/null +++ b/playbooks/organize_home.yml @@ -0,0 +1,130 @@ +--- +- name: Organize Home Directory based on XDG Specification + hosts: localhost + connection: local + gather_facts: no + + # This playbook helps organize your home directory by moving dotfiles + # into XDG standard directories (~/.config, ~/.local/share, ~/.cache). + # + # WHAT CAN'T BE DONE and WHY: + # 1. Automatic Backup: This playbook does not automatically back up your files. + # It is CRITICAL that you back up your dotfiles before running this playbook. + # A mistake could lead to data loss. + # + # 2. Sourcing Shell RC file: The playbook will update your .bashrc, but for the + # changes to take effect in your current terminal, you must manually source it + # with `source ~/.bashrc` or open a new terminal. + # + # 3. Risky Moves: Some application directories like .mozilla or .thunderbird + # are not moved because they can be complex and moving them might break + # profiles or extensions. It's safer to leave them in place. + # + # 4. Applications without standard way to change config path: Some applications + # do not follow XDG specs and do not provide an easy way to change their + ax_path. These are left untouched. + + vars: + home_dir: "{{ lookup('env', 'HOME') }}" + user: "{{ lookup('env', 'USER') }}" + + tasks: + - name: IMPORTANT - Manual Backup Reminder + pause: + prompt: | + This playbook will move files in your home directory. + PLEASE back up your dotfiles before proceeding. + Press Enter to continue if you have a backup, or Ctrl+C to abort. + + - name: Ensure XDG base directories exist + file: + path: "{{ item }}" + state: directory + mode: '0755' + loop: + - "{{ home_dir }}/.config" + - "{{ home_dir }}/.local/share" + - "{{ home_dir }}/.cache" + + - name: Move dotfiles and directories to XDG locations + block: + - name: Check if dotfile/directory exists + stat: + path: "{{ home_dir }}/{{ item.src }}" + register: stat_result + loop: + - { src: '.android', dest: '.config/android' } + - { src: '.ansible', dest: '.config/ansible' } + - { src: '.docker', dest: '.config/docker' } + - { src: '.npm', dest: '.cache/npm' } + - { src: '.nvm', dest: '.local/share/nvm' } + - { src: '.wine', dest: '.local/share/wine' } + - { src: '.steam', dest: '.local/share/Steam' } + - { src: '.yt-dlp', dest: '.config/yt-dlp' } + - { src: '.vim', dest: '.config/vim' } + - { src: '.python_history', dest: '.local/share/python/history' } + - { src: '.gitconfig', dest: '.config/git/config' } + - { src: '.gtkrc-2.0', dest: '.config/gtk-2.0/gtkrc' } + - { src: '.gtkrc-2.0-kde4', dest: '.config/gtk-2.0/' } + - { src: '.myclirc', dest: '.config/mycli/myclirc' } + - { src: '.tig_history', dest: '.local/share/tig/history' } + + - name: Move file or directory + command: "mv {{ home_dir }}/{{ item.item.src }} {{ home_dir }}/{{ item.item.dest }}" + when: item.stat.exists + loop: "{{ stat_result.results }}" + loop_control: + label: "Moving {{ item.item.src }}" + args: + # This makes the move idempotent. If the source is gone, it won't run. + removes: "{{ home_dir }}/{{ item.item.src }}" + + - name: Update .bashrc with XDG environment variables + blockinfile: + path: "{{ home_dir }}/.bashrc" + block: | + # XDG Base Directory Specification + export XDG_CONFIG_HOME="$HOME/.config" + export XDG_CACHE_HOME="$HOME/.cache" + export XDG_DATA_HOME="$HOME/.local/share" + export XDG_STATE_HOME="$HOME/.local/state" + + # Tell applications where to find their files + export ANDROID_PREFS_ROOT="$HOME/.config/android" + export ANSIBLE_CONFIG="$XDG_CONFIG_HOME/ansible/ansible.cfg" + export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker" + export NVM_DIR="$XDG_DATA_HOME/nvm" + export PYTHONHISTFILE="$XDG_DATA_HOME/python/history" + export WINEPREFIX="$XDG_DATA_HOME/wine" + marker: "# {mark} ANSIBLE MANAGED BLOCK - XDG VARS" + + - name: Update application-specific configurations + block: + - name: Configure mycli to use new log file path + ini_file: + path: "{{ home_dir }}/.config/mycli/myclirc" + section: main + option: log_file + value: "{{ home_dir }}/.cache/mycli/mycli.log" + create: yes + mode: '0644' + + - name: Configure vim to use new viminfo path + lineinfile: + path: "{{ home_dir }}/.config/vim/vimrc" + line: "set viminfo='100,n{{ home_dir }}/.local/share/vim/viminfo'" + create: yes + mode: '0644' + + - name: Configure tig to use new history file path + copy: + dest: "{{ home_dir }}/.config/tig/config" + content: "set history-file = {{ home_dir }}/.local/share/tig/history" + create: yes + mode: '0644' + + - name: Final instructions + debug: + msg: | + Playbook execution finished. + Please run `source ~/.bashrc` or open a new terminal for changes to take effect.