Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- dev-tools
# - docker-cli-only
- docker-desktop-dependency
- fzf
- gh_cli
- git
- hashicorp
Expand Down
2 changes: 2 additions & 0 deletions roles/env/files/.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ if ! shopt -oq posix; then
fi
fi

# BEGIN ANSIBLE MANAGED BLOCK: source .bashrc.d scripts
# customize prompt
for file in /home/$USER/.bashrc.d/*.sh; do
[ -r "$file" ] && source "$file"
done
# END ANSIBLE MANAGED BLOCK: source .bashrc.d scripts
38 changes: 12 additions & 26 deletions roles/env/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,35 @@
---
- name: install custom_bash.sh / git_bash_ps1.sh to home .bashrc.d directory
- name: ensure .bashrc.d directory exists in user's home
file:
path: "{{ home_dir }}/.bashrc.d"
state: directory
owner: "{{ local_user }}"
group: "{{ local_user_primary_group }}"
mode: "0750"

- name: install custom_bash.sh / git_bash_ps1.sh to {{ home_dir}}/.bashrc.d/
copy:
src: "{{ item }}"
dest: "/{{ home_dir }}/.bashrc.d/"
dest: "{{ home_dir }}/.bashrc.d/"
owner: "{{ local_user }}"
group: "{{ local_user_primary_group }}"
mode: "0640"
loop:
- custom_bash.sh
- fzf_config.sh
- git_bash_ps1.sh
- pyenv.sh

- name: deploy .bashrc / .dircolors to home directory
- name: ensure .bashrc sources from {{ home_dir }}/.bashrc.d / .dircolors to home directory
copy:
src: "{{ item }}"
dest: "/{{ home_dir }}/"
dest: "{{ home_dir }}/"
owner: "{{ local_user }}"
group: "{{ local_user_primary_group }}"
mode: "0640"
loop:
- .bashrc
- .dircolors

- name: install fzf
git:
repo: "https://github.com/junegunn/fzf.git"
dest: "{{ home_dir }}/.fzf"
depth: "1"
version: "master"

- name: check if fzf install script has been executed
shell: "/{{ home_dir }}/.fzf/bin/fzf --version"
register: fzf_installed
failed_when: false
changed_when: false

#- name: fzf_installed
#debug:
#msg: "{{ fzf_installed }}"

- name: run fzf install
shell: "/{{ home_dir }}/.fzf/install --key-bindings --completion --no-update-rc"
when: fzf_installed.rc != 0

- name: copy .gitconfig
copy:
src: gitconfig
Expand Down
101 changes: 101 additions & 0 deletions roles/fzf/files/fzf_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# fzf configuration

#export FZF_DEFAULT_COMMAND='rg --files --ignore-vcs --smart-case --hidden'
export FZF_DEFAULT_COMMAND='fdfind --type f --strip-cwd-prefix --hidden --follow --exclude .git'
export FZF_DEFAULT_OPTS="
--height 80%
--layout reverse
--multi
--border
--highlight-line --color gutter:-1,selected-bg:238,selected-fg:146,current-fg:189"

# Preview file content using bat (https://github.com/sharkdp/bat)
export FZF_CTRL_T_OPTS="
--walker-skip .git,node_modules,target
--preview 'batcat -n --color=always {}'
--bind 'ctrl-/:change-preview-window(down|hidden|)'"

# CTRL-P to toggle preview window to view full command
# CTRL-Y to copy the command into clipboard using pbcopy
export FZF_CTRL_R_OPTS="
--preview 'echo {}' --preview-window up:3:hidden:wrap
--bind 'ctrl-p:toggle-preview'
--bind 'ctrl-y:execute-silent(echo -n {2..} | xclip -selection clipboard)+abort'
--color header:italic
--header '
Press CTRL-P: toggle preview
Press CTRL-Y to copy command into clipboard
'"

# Print tree structure in the preview window
export FZF_ALT_C_OPTS="
--walker-skip .git,node_modules,target
--preview 'tree -C {} | head -200'"

export EDITOR=vim

# original function obtained from:
# https://thevaluable.dev/practical-guide-fzf-example/
se() {
local search_folder="${1:-$HOME}"

# Common folders to exclude from traversal
local exclude_paths=(
"$HOME/.cache"
"$HOME/.config"
"$HOME/.local"
"$HOME/.codeium"
"$HOME/.git"
"$HOME/.vscode"
"$HOME/.npm"
"$HOME/.cargo"
"$HOME/.rustup"
"$HOME/.mozilla"
"$HOME/.snap"
)

# Build prune expression for find
local prune_expr=""
for path in "${exclude_paths[@]}"; do
prune_expr+=" -path \"$path\" -o"
done
# Remove trailing -o
prune_expr="${prune_expr::-3}"

selection=$(
eval "find \"$search_folder\" \( $prune_expr \) -prune -o -type d -print" | fzf \
--preview='command -v tree >/dev/null && tree -C {} || ls -la {}' \
--preview-window='50%' \
--prompt='Dirs > ' \
--bind='del:execute(rm -ri {+})' \
--bind='ctrl-p:toggle-preview' \
--bind='ctrl-d:change-prompt(Dirs > )' \
--bind="ctrl-d:+reload(eval \"find '$search_folder' \\( ${prune_expr//\"/\\\"} \\) -prune -o -type d -print\")" \
--bind='ctrl-d:+change-preview(command -v tree >/dev/null && tree -C {} || ls -la {})' \
--bind='ctrl-d:+refresh-preview' \
--bind='ctrl-f:change-prompt(Files > )' \
--bind="ctrl-f:+reload(eval \"find '$search_folder' \\( ${prune_expr//\"/\\\"} \\) -prune -o -type f -print\")" \
--bind='ctrl-f:+change-preview(command -v batcat >/dev/null && batcat --color=always {} || cat {})' \
--bind='ctrl-f:+refresh-preview' \
--bind='ctrl-a:select-all' \
--bind='ctrl-x:deselect-all' \
--color header:italic \
--header '
CTRL-D to display directories
CTRL-F to display files
CTRL-A/CTRL-X to select/deselect all
ENTER to navigate | DEL to delete
CTRL-P to toggle preview
'
)

if [ -d "$selection" ]; then
cd "$selection" || return
elif [ -f "$selection" ]; then
cd "$(dirname "$selection")" || return
elif [ -n "$selection" ]; then
${EDITOR:-vim} "$selection"
fi
}

[ -f ~/.fzf.bash ] && source ~/.fzf.bash
63 changes: 63 additions & 0 deletions roles/fzf/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
- block:
- name: ensure .bashrc.d directory exists in user's home
file:
path: "{{ home_dir }}/.bashrc.d"
state: directory
owner: "{{ local_user }}"
group: "{{ local_user_primary_group }}"
mode: "0750"

- name: ensure .bashrc sources scripts from .bashrc.d
ansible.builtin.blockinfile:
path: "/{{ home_dir }}/.bashrc"
marker: "# {mark} ANSIBLE MANAGED BLOCK: source .bashrc.d scripts"
block: |
# customize prompt
for file in /home/$USER/.bashrc.d/*.sh; do
[ -r "$file" ] && source "$file"
done
owner: "{{ local_user }}"
group: "{{ local_user_primary_group }}"
mode: "0640"

- name: install fzf_config.sh to {{ home_dir}}/.bashrc.d/
copy:
src: "{{ item }}"
dest: "{{ home_dir }}/.bashrc.d/"
owner: "{{ local_user }}"
group: "{{ local_user_primary_group }}"
mode: "0640"
loop:
- fzf_config.sh

- name: install fzf
git:
repo: "https://github.com/junegunn/fzf.git"
dest: "{{ home_dir }}/.fzf"
depth: "1"
version: "master"

- name: check if fzf install script has been executed
shell: "{{ home_dir }}/.fzf/bin/fzf --version"
register: fzf_installed
failed_when: false
changed_when: false

- name: display fzf version if installed
debug:
msg: "fzf version installed: {{ fzf_installed.stdout }}"
when: fzf_installed.rc == 0

- name: run fzf install
shell: "{{ home_dir }}/.fzf/install --key-bindings --completion --no-update-rc"
when: fzf_installed.rc != 0

- name: display fzf uninstallation instructions
debug:
msg: |
=== Uninstallation Instructions ===
To uninstall fzf:
rm -rf {{ home_dir }}/.fzf
tags: ['fzf', 'upgrade']
become: false
Loading