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

Add change_directory command #9613

Closed
wants to merge 1 commit into from

Conversation

godalming123
Copy link

@godalming123 godalming123 commented Feb 12, 2024

Adds a command to change the working directory to the selected text. This would make it easier to (for example) embed a file-manager in helix (#9607) with the following code:

[keys.normal]
C-f = [":new", ":insert-output pwd; ls -F1", ":goto 2"]
# Mode for the file picker, TODO activate when the user presses control-f in normal mode
# 3 roadblocks:
# - activate modes from keymaps
# - if statements so that their can be 1 key to open the directory *or* the file (out of scope for the config file maybe)
# - using the escape key in custom modes
[keys.normal."_"]
esc = [":buffer-close!"]
f = ["extend_to_line_bounds", "goto_file", ":buffer-previous", ":buffer-close!"]
h = [":change-current-directory ../", "select_all", "delete_selection", ":insert-output pwd; ls -F1 --indicator-style=none", ":goto 2"]
d = ["extend_to_line_bounds", "change_directory", "select_all", "delete_selection", ":insert-output pwd; ls -F1", ":goto 2"] # Changes the current working directory to the directory under the cursor
j = "move_line_down"
k = "move_line_up"

Note that this PR only has the code, documentation still needs to be written

I plan to add a command to change the current mode in a subsequent PR so that pressing control-f could automatically open the normal."_" mode, and from that mode when a key is pressed the mode does not have to exit because it can change the mode to itself againt (tommorow maybe)

@kirawi
Copy link
Member

kirawi commented Feb 12, 2024

If I'm understanding this correctly, you would be able to achieve this with #4709 using existing commands. However, I also know people use tmux/zellij to send keystrokes to Helix to do this kind of stuff too #8314 #2177

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a hack around not having macro keybindings #1383 - you would use :cd <C-r>"<ret> instead. We don't generally accept 'bandaid' fixes around missing features and I don't see this command being useful once macro keybindings or scripting is possible: you would use :cd and registers interactively (i.e. outside of keybindings).

@the-mikedavis the-mikedavis added S-needs-discussion Status: Needs discussion or design. A-command Area: Commands labels Feb 12, 2024
@godalming123
Copy link
Author

See #9607 (reply in thread)

@godalming123 godalming123 deleted the patch-1 branch February 14, 2024 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-command Area: Commands S-needs-discussion Status: Needs discussion or design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants