Skip to content

Commit

Permalink
feat: load plugin only if command exists in system or if custom `when…
Browse files Browse the repository at this point in the history
…` is true

Add plugins:
- brew
- composer
- go
- gulp
- httpie
- rake
- symfony2

Closes #2
  • Loading branch information
popstas committed Apr 2, 2017
1 parent d5f8aae commit e9288c2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
45 changes: 31 additions & 14 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,51 @@ zsh_path:
- /usr/local/games

# fzf_widget extracted to variable for testing purposes
fzf_widgets: ytet5uy4/fzf-widgets
fzf_widgets: popstas/fzf-widgets

zsh_antigen_bundles:
#- command-not-found # +900 ms on OSX!!
- debian
zsh_check_commands:
- brew
- composer
- docker
- docker-compose
- go
- gulp
- http
- pip
- rake
- symfony
- tmux
- vagrant

zsh_antigen_bundles:
- { name: command-not-found, when: ansible_os_family != "Darwin" } # +900 ms on OSX!!
- { name: brew, command: brew }
- { name: composer, command: composer }
- { name: debian, when: ansible_os_family == "Debian" }
- { name: docker, command: docker }
- { name: docker-compose, command: docker-compose }
- fancy-ctrl-z
- git-extras
- gnu-utils
- pip
- { name: httpie, command: http }
- { name: go, command: go }
- { name: gulp, command: gulp }
- { name: pip, command: pip }
- { name: rake, command: rake }
- { name: symfony2, command: symfony }
- python
- tmux
- vagrant
- { name: tmux, command: tmux }
- { name: vagrant, command: vagrant }
- zsh_reload

- zsh-users/zsh-autosuggestions
- popstas/zsh-command-time
- unixorn/autoupdate-antigen.zshplugin
- urbainvaes/fzf-marks # replaces jump plugin, mark, jump and Ctrl+G
- "{{ fzf_widgets }}"

#- tysonwolker/iterm-tab-colors # random tab colors depends of pwd
#- wbinglee/zsh-wakatime
#- denolfe/zsh-travis # git-trav, go to travis of project
#- Tarrasch/zsh-bd # bd, back directory

- zsh-users/zsh-syntax-highlighting # must be last
# must be last, don't work on zsh < 4.3.17
- name: zsh-users/zsh-syntax-highlighting
when: "{{ zsh_register_version.stdout | version_compare('4.3.17', '>=') }}"

zsh_antigen_theme: "bhilburn/powerlevel9k powerlevel9k"

Expand Down
7 changes: 7 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---

- name: Check commands exists
command: "which {{ item }}"
with_items: "{{ zsh_check_commands }}"
failed_when: false
changed_when: false
register: zsh_register_commands_exists

- name: Check zsh version
shell: "zsh --version | cut -d ' ' -f2"
register: zsh_register_version
Expand Down
35 changes: 27 additions & 8 deletions templates/zshrc.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,35 @@ source {{ zsh_antigen_path }}/antigen/antigen.zsh
antigen use oh-my-zsh

{% for bundle in zsh_antigen_bundles -%}
{%- if 'zsh-syntax-highlighting' in bundle -%}
{% if zsh_register_version.stdout | version_compare('4.3.17', '>=') -%}
# https://github.com/zsh-users/zsh-syntax-highlighting/issues/286#issuecomment-284261033,
# will fixed after zsh-autosuggestion v0.3.3
{%- if 'zsh-syntax-highlighting' in bundle or bundle is mapping and 'zsh-syntax-highlighting' in bundle.name -%}
# will fixed in zsh-autosuggestion v0.4 - https://github.com/zsh-users/zsh-autosuggestions/pull/218
if (( ZSHRC_LOAD_ONCE++ == 0 )); then
antigen bundle {{ bundle }}
antigen bundle {% if bundle is mapping %}{{ bundle.name }}{% else %}{{ bundle }}{% endif %}

fi
{%- endif %}
{% else -%}
antigen bundle {{ bundle }}
{%- else -%}
{%- if bundle is mapping -%}
{% set valid = true -%}
{% set command_not_exists = [] -%}

{%- if bundle.when is defined and not bundle.when -%}
{% set valid = false -%}
{% endif -%}

{% if bundle.command is defined -%}
{% for cmd in zsh_register_commands_exists.results -%}
{% if cmd.cmd[1] == bundle.command and cmd.rc == 1 -%}
{% if command_not_exists.append(1) %}{% endif -%}
{% endif -%}
{% endfor -%}
{% endif -%}

{% if valid and not command_not_exists %}
antigen bundle {{ bundle.name }}
{% endif %}
{%- else %}
antigen bundle {{ bundle }}
{% endif %}
{% endif -%}
{% endfor %}

Expand Down

0 comments on commit e9288c2

Please sign in to comment.