-
-
Save appblue/11be219e961da8e7fa67b2d07bbb2df7 to your computer and use it in GitHub Desktop.
List old Nvim Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Script to list recent files and open nvim using fzf | |
| # set to an alias nlof in .zshrc | |
| list_oldfiles() { | |
| # Get the oldfiles list from Neovim | |
| local oldfiles=($(nvim -u NONE --headless +'lua io.write(table.concat(vim.v.oldfiles, "\n") .. "\n")' +qa)) | |
| # Filter invalid paths or files not found | |
| local valid_files=() | |
| for file in "${oldfiles[@]}"; do | |
| if [[ -f "$file" ]]; then | |
| valid_files+=("$file") | |
| fi | |
| done | |
| # Use fzf to select from valid files | |
| local files=($(printf "%s\n" "${valid_files[@]}" | | |
| grep -v '\[.*' | | |
| fzf --multi \ | |
| --preview 'bat -n --color=always --line-range=:500 {} 2>/dev/null || echo "Error previewing file"' \ | |
| --height=70% \ | |
| --layout=default)) | |
| # Open selected files in Neovim | |
| [[ ${#files[@]} -gt 0 ]] && nvim "${files[@]}" | |
| } | |
| # Call the function | |
| list_oldfiles "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment