gotbletu/shownotes

HiddenFiles

Closed this issue · 5 comments

Hey There, Any Idea how to modify fzf_select to incorporate hidden files but ignore .git directories at the same time?

just add -name .git

e.g

class fzf_hiddenwithoutgit(Command):
    """
  fzf_hiddenwithoutgit show hidden files but not .git folders
    """
    def execute(self):
        import subprocess
        if self.quantifier:
            # match only directories
            command="find -L . \( -name .git -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
            -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m"
        else:
            # match files and directories
            command="find -L . \( -name .git -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
            -o -print 2> /dev/null | sed 1d | cut -b3- | fzf +m"
        fzf = self.fm.execute_command(command, stdout=subprocess.PIPE)
        stdout, stderr = fzf.communicate()
        if fzf.returncode == 0:
            fzf_file = os.path.abspath(stdout.decode('utf-8').rstrip('\n'))
            if os.path.isdir(fzf_file):
                self.fm.cd(fzf_file)
            else:
                self.fm.select_file(fzf_file)

Hi there gotbletu; big Fan by the way;
I am curious how would you implement that in a fzfrc file?
I am trying to keep all my fzf customization in one file;

Here is what I mean, Link: fzfrc

just add to your function

fzf_test() { find . | grep -v .git | sed -n '1!p' | fzf ;}

Believe me when I say I Am annoying; Last time and I close this;
Here is what I have; two functions, both use the selct_File Function inside respectively;

#--- Custom searches ---#

Selecting Variable

select_file() {
  given_file="$1"
  fzf --preview="cat {}" --preview-window=right:70%:wrap --query="$given_file"
}

Full system search with preview and EDITOR setup

f/() {
  cd /
  previous_file="$1"
  file_to_edit=`select_file $previous_file`

  if [ -n "$file_to_edit" ] ; then
    "$EDITOR" "$file_to_edit"
    main "$file_to_edit"
  fi
}

Full home folder search with preview and EDITOR setup

fh() {
 cd /home/niko
  previous_file="$1"
  file_to_edit=`select_file $previous_file`

  if [ -n "$file_to_edit" ] ; then
    "$EDITOR" "$file_to_edit"
    main "$file_to_edit"
  fi
}

.................................................................................................................

What I am trying to reach:

Ignore .git folders.
use bat instead of cat to get preview with syntax Highlighting.

I like to use this already setup functions because they have the $EDITOR Variable in it and they also have the preview feature integrated as well, which is also hard for me to understand how it works. Sorry for keep asking the same thing giving the fact that you already answer.

Thanks again.
....................................................................................................................

I tiring to get it to work but I am having trouble with it.

OK I finally got it!

select_file() {
	given_file="$1"
	fzf --query="$given_file"
}

I modify the select_file Variable and the .Xprofile Env Variable.:

export FZF_DEFAULT_COMMAND='fd --type file --follow --hidden --exclude .git'

Fuzzy Finder Options to use Bat and previews with syntax-highlithing.

export FZF_DEFAULT_OPTS="--ansi --preview-window 'right:60%' --preview 'bat --color=always --style=header,grid --line-range :300 {}'"