commit 27dbb4e03238853f46de1ce5e1e7b405c901b459 Author: Blallo Date: Fri Aug 7 19:59:07 2020 +0200 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8000dd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vagrant diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cd12389 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM debian:buster + +ARG UID 1000 +ARG GID 1000 +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update \ + && apt-get install -y \ + openssh-server \ + supervisord \ + && apt-get autoremove -y \ + && apt-get clean \ + && rm -fr /var/lib/apt/lists/* \ + && groupadd -g ${GID} chic \ + && useradd -u ${UID} -g ${GID} plinio + +COPY docker/supervisord.conf /etc/supervisord.conf +EXPOSE 2222 + +ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a2b4bca --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +build: + docker build -t zsh_chic_ansible:latest . + +run: + ansible diff --git a/README.md b/README.md new file mode 100644 index 0000000..6d0f98b --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Zsh chic + +An ansible role to ensure your zsh is très chic + +### How + +Feed something like this to your role + +```yml +zsh_chic: + users: + - username: root + home: /root + group: root + antibody: true + - username: qui + home: /home/qui + group: qui + starship: true + - username: quo + home: /home/quo + group: quo + antibody: true + - username: qua + home: /home/qua + group: qua +``` + +**WARNING**: this role is suited only for debian (buster and maybe bullseye). diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..131b0ac --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,31 @@ +# This guide is optimized for Vagrant 1.7 and above. +# Although versions 1.6.x should behave very similarly, it is recommended +# to upgrade instead of disabling the requirement below. +Vagrant.require_version ">= 1.7.0" + +Vagrant.configure(2) do |config| + + config.vm.box = "debian/buster64" + + config.vm.define "debiantest" do |m| + m.vm.hostname = "debiantest" + m.vm.network :private_network, ip: "192.168.123.2", libvirt__dhcp_enabled: false + m.vm.synced_folder ".", "/vagrant", disabled: true + end + # Disable the new default behavior introduced in Vagrant 1.7, to + # ensure that all Vagrant machines will use the same SSH key pair. + # See https://github.com/mitchellh/vagrant/issues/5005 + config.ssh.insert_key = false + + config.vm.provider :libvirt do |lv| + lv.cpus = 2 + lv.memory = 1024 + end + + config.vm.provision "ansible" do |ansible| + ansible.become = true + ansible.verbose = "v" + ansible.playbook = "playbook.yml" + ansible.inventory_path = "inventory" + end +end diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..613d83b --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +roles_path = ../ diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..e562c41 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,4 @@ +--- +zsh_chic: + antibody: false + starship: false diff --git a/files/starship.toml b/files/starship.toml new file mode 100644 index 0000000..635e4c0 --- /dev/null +++ b/files/starship.toml @@ -0,0 +1,5 @@ +[hostname] +ssh_only = false +prefix = "⟪" +suffix = "⟫" +disabled = false diff --git a/inventory b/inventory new file mode 100644 index 0000000..edb98dc --- /dev/null +++ b/inventory @@ -0,0 +1 @@ +debiantest diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..59a1de5 --- /dev/null +++ b/playbook.yml @@ -0,0 +1,15 @@ +--- +- hosts: debiantest + gather_facts: yes + vars_files: + - ./test_vars.yml + pre_tasks: + - name: Add dummy users + user: + name: "{{ item.username }}" + state: present + password: $6$LqIjU1/Cd$Uou/9gTKyP/qPHnI0EWcuUYg.7DsI9zNOTeDUWk8pH7/.ncgZGwIGXupGRxPNtqw/w6p/6Ls84Bddvfu3D9p9/ + with_items: "{{ zsh_chic.users }}" + + roles: + - zsh_chic diff --git a/tasks/antibody.yml b/tasks/antibody.yml new file mode 100644 index 0000000..84ce3a6 --- /dev/null +++ b/tasks/antibody.yml @@ -0,0 +1,21 @@ +--- +- name: Download antibody installer + get_url: + url: https://git.io/antibody + dest: /tmp/antibody-installer.sh + owner: root + group: root + mode: 0755 + +- name: Run antibody installer + shell: + cmd: /tmp/antibody-installer.sh + chdir: /usr + +- name: Copy antibody plugin list + template: + src: templates/antibody.plugins.zsh.j2 + dest: /usr/share/zsh/antibody.plugins.zsh + owner: root + group: root + mode: 0755 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..97cbe2c --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,67 @@ +--- +- name: Ensure zsh is present + apt: + name: + - zsh + - tmux + - fzf + - curl + - git + - fasd + - ripgrep + state: present + +- name: Obtain bat .deb package + get_url: + url: https://github.com/sharkdp/bat/releases/download/v0.13.0/bat_0.13.0_amd64.deb + dest: /tmp/bat_0.13.0_amd64.deb + owner: root + group: root + mode: 0755 + register: new_bat_deb + +- name: Install bat + shell: dpkg -i /tmp/bat_0.13.0_amd64.deb + when: new_bat_deb is defined and new_bat_deb.changed + +- include_tasks: antibody.yml + +- include_tasks: starship.yml + +- include_tasks: powerline.yml + +- name: Clone fzf repo to get completion and keybindings + git: + repo: 'https://github.com/junegunn/fzf' + dest: /opt/fzf + +- name: Install zshrc template for each provided user + template: + src: templates/zshrc.j2 + dest: "{{ item.home }}/.zshrc" + owner: "{{ item.username }}" + group: "{{ item.group|default(item.username) }}" + mode: 0644 + vars: + antibody: "{{ item.antibody|default(false) }}" + starship: "{{ item.starship|default(false) }}" + powerline: "{{ item.powerline|default(false) }}" + locale: "{{ item.locale|default('en_US.UTF-8') }}" + term: "{{ item.term|default(None) }}" + with_items: "{{ zsh_chic.users }}" + +- name: Set zsh as default shell for each provided user + user: + name: "{{ item.username }}" + shell: /bin/zsh + with_items: "{{ zsh_chic.users }}" + +- name: Copy starship config for use who use it + copy: + src: files/starship.toml + dest: "{{ item.home }}/.starship.toml" + owner: "{{ item.username }}" + group: "{{ item.group|default(item.username) }}" + mode: 0644 + when: item.starship is defined and item.starship + with_items: "{{ zsh_chic.users }}" diff --git a/tasks/powerline.yml b/tasks/powerline.yml new file mode 100644 index 0000000..5d0e6df --- /dev/null +++ b/tasks/powerline.yml @@ -0,0 +1,5 @@ +--- +- name: Install powerline + apt: + name: powerline + state: present diff --git a/tasks/starship.yml b/tasks/starship.yml new file mode 100644 index 0000000..ac024ff --- /dev/null +++ b/tasks/starship.yml @@ -0,0 +1,19 @@ +--- +- name: Download starship binary + get_url: + url: https://github.com/starship/starship/releases/download/{{ version }}/starship-x86_64-unknown-linux-gnu.tar.gz + dest: /root/starship.tar.gz + owner: root + group: root + mode: 0755 + vars: + version: "v0.39.0" + +- name: Extract and install starship binary + unarchive: + src: /root/starship.tar.gz + dest: /usr/local/bin + remote_src: yes + owner: root + group: root + mode: 0755 diff --git a/templates/antibody.plugins.zsh.j2 b/templates/antibody.plugins.zsh.j2 new file mode 100644 index 0000000..a9bb484 --- /dev/null +++ b/templates/antibody.plugins.zsh.j2 @@ -0,0 +1,13 @@ +leophys/ohmyzsh path:lib +leophys/ohmyzsh path:themes/agnoster-server.zsh-theme +leophys/ohmyzsh path:plugins/colored-man-pages +leophys/ohmyzsh path:plugins/docker +leophys/ohmyzsh path:plugins/gitfast + +ael-code/zsh-gpg-agent +ael-code/zsh-plugin-fasd-fzf +ael-code/zsh-colored-man-pages +leophys/zsh-plugin-fzf-finder +zsh-users/zsh-autosuggestions +junegunn/fzf +wfxr/forgit diff --git a/templates/zshrc.j2 b/templates/zshrc.j2 new file mode 100644 index 0000000..9b8c989 --- /dev/null +++ b/templates/zshrc.j2 @@ -0,0 +1,98 @@ +# Local pre scripts + +if [[ -d $HOME/.config/zsh/pre ]] && [[ "$(ls $HOME/.config/zsh/pre)" ]] ; then + for script in $HOME/.config/zsh/pre/*; do + . $script + done +fi + +# Locales +export LANG={{ locale }} +export LANGUAGE={{ locale.split(".")[0] }} +export LC_CTYPE="{{ locale }}" +export LC_NUMERIC="{{ locale }}" +export LC_TIME="{{ locale }}" +export LC_COLLATE="{{ locale }}" +export LC_MONETARY="{{ locale }}" +export LC_MESSAGES="{{ locale }}" +export LC_PAPER="{{ locale }}" +export LC_NAME="{{ locale }}" +export LC_ADDRESS="{{ locale }}" +export LC_TELEPHONE="{{ locale }}" +export LC_MEASUREMENT="{{ locale }}" +export LC_IDENTIFICATION="{{ locale }}" +export LC_ALL= + +{% if term is defined and term != "" %} +export TERM={{ term }} +{% endif -%} + + +{% if antibody %} +autoload -Uz compinit +compinit +source <(antibody init) +source /usr/share/doc/fzf/examples/key-bindings.zsh +antibody bundle < /usr/share/zsh/antibody.plugins.zsh +{% endif -%} + +{% if starship %} +autoload -U select-word-style +select-word-style bash +HISTFILE=~/.zsh_history +HISTSIZE=10000 +SAVEHIST=10000 +setopt appendhistory + +export STARSHIP_CONFIG=${HOME}/.starship.toml +eval "$(starship init zsh)" +{% endif -%} + +source /opt/fzf/shell/completion.zsh +source /opt/fzf/shell/key-bindings.zsh + +eval "$(fasd --init auto)" + +alias t="tmux -2" +alias sy="systemctl" +alias ssy="sudo systemctl" +alias syu="systemctl --user" +alias ls="ls --color=tty" +alias l="ls -1" +alias lt="ls -lt" +alias lh="ls -lh" +alias la="ls -la" +alias ll="ls -l" +alias lrt="ls -lrt" +alias vf="cd \$(git rev-parse --show-toplevel)" +alias vvf="cd \$(${HOME}/.bin/vvf.sh)" + +{% if localbin is defined %} +if [ -d ${HOME}/{{ localbin }} ]; then + export PATH=${HOME}/{{ localbin }}:$PATH +fi +{% endif %} + +{% if powerline %} +if which powerline-daemon > /dev/null; then + powerline-daemon -q + POWERLINE_ZSH=/usr/share/powerline/bindings/zsh/powerline.zsh + if [ -f ${POWERLINE_ZSH} ]; then + . ${POWERLINE_ZSH} + fi +fi +{% endif %} + +# Local post scripts + +if [[ -d $HOME/.config/zsh/post ]] && [[ "$(ls $HOME/.config/zsh/post)" ]] ; then + for script in $HOME/.config/zsh/post/*; do + . $script + done +fi + +if [ -f ${HOME}/.zshrc.local ]; then + source ${HOME}/.zshrc.local +fi + +# vim: et sw=2 ts=2 diff --git a/test_vars.yml b/test_vars.yml new file mode 100644 index 0000000..3830981 --- /dev/null +++ b/test_vars.yml @@ -0,0 +1,33 @@ +--- +zsh_chic: + users: + - username: root + home: /root + group: root + antibody: true + - username: qui + home: /home/qui + group: qui + starship: true + - username: quo + home: /home/quo + group: quo + antibody: true + - username: qua + home: /home/qua + group: qua + - username: pk + home: /home/pk + group: pk + antibody: false + starship: false + - username: uno + home: /home/uno + group: uno + antibody: true + - username: due + home: /home/due + group: due + starship: true + antibody: false + starship: true