diff --git a/roles/shell/tasks/main.yml b/roles/shell/tasks/main.yml index 3cb09e0..d45a957 100644 --- a/roles/shell/tasks/main.yml +++ b/roles/shell/tasks/main.yml @@ -15,3 +15,13 @@ - name: Setup starship ansible.builtin.include_tasks: setup_starship.yml when: starship_installed.rc != 0 + +- name: Check if direnv already installed + ansible.builtin.command: which direnv + register: direnv_installed + changed_when: false + failed_when: false + +- name: Setup direnv + ansible.builtin.include_tasks: setup_direnv.yml + when: direnv_installed.rc != 0 diff --git a/roles/shell/tasks/setup_direnv.yml b/roles/shell/tasks/setup_direnv.yml new file mode 100644 index 0000000..5e1cd02 --- /dev/null +++ b/roles/shell/tasks/setup_direnv.yml @@ -0,0 +1,22 @@ +--- + +- name: Install direnv in Ubuntu + become: yes + ansible.builtin.apt: + name: direnv + when: ansible_distribution == "Ubuntu" + +- name: Install direnv in MacOSX + community.general.homebrew: + name: direnv + when: ansible_distribution == "MacOSX" + +- name: Set shell info + ansible.builtin.set_fact: + shell_info: "{{ ansible_user_shell | shell_config }}" + +- name: Setup direnv hook + ansible.builtin.lineinfile: + path: "{{ ansible_user_dir }}/{{ shell_info.rc_file }}" + regexp: "^eval \"$(direnv hook {{ shell_info.name }})\"" + line: "eval \"$(direnv hook {{ shell_info.name }})\"" diff --git a/roles/shell/tasks/setup_starship.yml b/roles/shell/tasks/setup_starship.yml index 7bdc658..7853eb7 100644 --- a/roles/shell/tasks/setup_starship.yml +++ b/roles/shell/tasks/setup_starship.yml @@ -26,3 +26,20 @@ src: starship.toml dest: "{{ ansible_user_dir }}/.config/starship.toml" mode: '0644' + +- name: Set window title for bash + ansible.builtin.blockinfile: + path: "{{ ansible_user_dir }}/{{ shell_info.rc_file }}" + marker: "# {mark} ANSIBLE MANAGED BLOCK shell wintitle" + block: | + function set_win_title(){ + local current_path="$PWD" + if [[ "$current_path" == "$HOME" ]]; then + current_path="~" + elif [[ "$current_path" == "$HOME"/* ]]; then + current_path="~${current_path#$HOME}" + fi + echo -ne "\033]0;${USER}@${HOSTNAME}: ${current_path}\007" + } + starship_precmd_user_func="set_win_title" + when: ansible_user_shel == '/bin/bash'