Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Feature Request) Open marked files with default $EDITOR #35

Open
nerd190 opened this issue Aug 30, 2020 · 5 comments
Open

(Feature Request) Open marked files with default $EDITOR #35

nerd190 opened this issue Aug 30, 2020 · 5 comments

Comments

@nerd190
Copy link

nerd190 commented Aug 30, 2020

Hi, first of all.... this is amazing, THANK YOU!!!
When I saw this initially, I thought, as it can mark files as well as directories, that pressing ENTER on a file would open the file just as it does a directory, but it appears that it just navigates to the file's directory instead.
I think it would be alot nicer to open any mark, not just directories, otherwise marking files is not needed, we can already just mark the directory instead which is better.
For example: I marked my 'zshrc' & 'bashrc' when I could've just marked '/etc' instead which gives me access to both files through one shortcut.

My feauture request would make FZM's file marking a very valuable feature!
FZM could default to: default $EDITOR (if set)
If not: look for 'nano' & 'vi/vim' as both of these editors are pre-installed in most distros now unless...
a variable for us to set like: "FZM_EDITOR" to let us pick our own, this could serve an extra purpose also! adding this means we could fill up FZM with all of our project's files and have them open in vim, but still have my default editor set as micro for opening normal txt/rc/configs when outside of FZM.
Thank you again.

@urbainvaes
Copy link
Owner

Hi,

Thank you very much for your suggestion! This does sound like it could be very useful, but how would you suggest marking files? At the moment, the command mark only works for directories, right?

@nerd190
Copy link
Author

nerd190 commented Sep 3, 2020

No problem at all, I really like this utility so thank YOU!
I am currently at work but had a quick look at the script, whilst this is completely untested so will probably not work, it should show a rough idea of what I was thinking, something like:

  • mark function:
function mark {
    local mark_to_add
### New Checks To Save As Either A File Or Directory & If Either Have A Title:
    # If no args: Add current directory with no title.
    if [[ "$#" -eq 0 ]]; then
        mark_to_add="$(pwd)"
    fi
    # If 1 arg: Check if its a file, if true, its a file with no title.
    if [[ "$#" -eq 1 ]] && [[ -f "$mark_to_add" ]]; then
        mark_to_add="$(pwd)/$1"
    else
    # Its a directory with a "title".
        mark_to_add="$1 : $(pwd)"
    fi
    if [[ "$#" -ge 2 ]] && [[ -f "$mark_to_add" ]]; then
    # If 2 or more args & 1st is a file: Then its a file with a title. Any args EXCEPT from the 1st are treated as title too. E.g: An UNQUOTED Title With Spaces.
        mark_to_add="${@:2} :  $(pwd)/$1"
    else
    # Its a directory with a "title". Any args EXCEPT from 1st are treated as the title too.
        mark_to_add="${@:1} : $(pwd)"
    fi
### End.
    if grep -qxFe "${mark_to_add}" "${FZF_MARKS_FILE}"; then
        echo "** The following mark already exists **"
    else
        echo "${mark_to_add}" >> "${FZF_MARKS_FILE}"
        echo "** The following mark has been added **"
    fi
    echo "${mark_to_add}" | _color_marks
    setup_completion
}
  • Jump function:
function jump {
    local jumpline jumpdir bookmarks
    if [[ $1 == "-->-->-->" ]]; then
        jumpline=$2
    else
        jumpline=$(_color_marks < "${FZF_MARKS_FILE}" | eval $
    fi
    if [[ -n ${jumpline} ]]; then
        jumpdir=$(echo "${jumpline}" | sed 's/.*: \(.*\)$/\1/'
        bookmarks=$(_handle_symlinks)
### Check "jumdir" is a directory, or a file:
        if [[ -f "${jumpdir}" ]]; then
            # is a file, open in our text editor.
            $EDITOR "${jumpdir}" || nano "$jumpdir" || vim "$jumpdir" || vi "jumpdir"
        else
            # Is a directory.
            cd "${jumpdir}" || return

            if ! [[ "${FZF_MARKS_KEEP_ORDER}" == 1 ]]; then
                perl -n -i -e "print unless /^\\Q${jumpline//\
                echo "${jumpline}" >> "${FZF_MARKS_FILE}"
            fi
        fi
    fi
}

@urbainvaes
Copy link
Owner

Thank you very much for this! I will have a careful look in the weekend and get back to you then.

@urbainvaes
Copy link
Owner

urbainvaes commented Sep 22, 2020

Hi 5c0tt-b0t,

Sorry for being a bit slow with this. But since the suggested change is quite significant, I think it's good to take some time before incorporating it.

I really like the idea, though, and think it would be very useful for frequently edited files such as .vimrc etc. Your suggested user interface looks nice, too. Thank you very much for your work!

One thing I wonder is whether the interface might be a bit complex to remember, since quite a few cases are considered. It might be cleaner (though a bit more verbose), to add a flag -f FILENAME in order to explicity add a mark to a file? What do you think? The interface would then be

mark LABEL

to add a mark with label LABEL to the current directory, and

mark -f FILENAME LABEL

to add a mark with label LABEL (possibly containing spaces) to the file FILENAME. What do you think?

@nerd190
Copy link
Author

nerd190 commented Sep 26, 2020

dont apologise! i agree the script i used above as an example has alot of checks and I was actually going to re-write it with flags too to make it alot simpler! I like this idea! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants