Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
d8888719
Unverified
Commit
d8888719
authored
Nov 25, 2020
by
Marc Cornellà
Committed by
GitHub
Nov 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(magic-enter): fix various bugs in the plugin (#9466)
parent
7a76afd6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
21 deletions
+32
-21
magic-enter.plugin.zsh
plugins/magic-enter/magic-enter.plugin.zsh
+32
-21
No files found.
plugins/magic-enter/magic-enter.plugin.zsh
View file @
d8888719
# Bind quick stuff to enter!
#
# Pressing enter in a git directory runs `git status`
# in other directories `ls`
magic-enter
()
{
# If commands are not already set, use the defaults
[
-z
"
$MAGIC_ENTER_GIT_COMMAND
"
]
&&
MAGIC_ENTER_GIT_COMMAND
=
"git status -u ."
[
-z
"
$MAGIC_ENTER_OTHER_COMMAND
"
]
&&
MAGIC_ENTER_OTHER_COMMAND
=
"ls -lh ."
# Default commands
:
${
MAGIC_ENTER_GIT_COMMAND
:
=
"git status -u ."
}
# run when in a git repository
:
${
MAGIC_ENTER_OTHER_COMMAND
:
=
"ls -lh ."
}
# run anywhere else
if
[[
-z
$BUFFER
]]
;
then
echo
""
if
git rev-parse
--is-inside-work-tree
&>/dev/null
;
then
eval
"
$MAGIC_ENTER_GIT_COMMAND
"
else
eval
"
$MAGIC_ENTER_OTHER_COMMAND
"
fi
zle redisplay
magic-enter
()
{
# Only run MAGIC_ENTER commands when in PS1 and command line is empty
# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#User_002dDefined-Widgets
if
[[
-n
"
$BUFFER
"
||
"
$CONTEXT
"
!=
start
]]
;
then
return
fi
if
command
git rev-parse
--is-inside-work-tree
&>/dev/null
;
then
BUFFER
=
"
$MAGIC_ENTER_GIT_COMMAND
"
else
zle accept-line
BUFFER
=
"
$MAGIC_ENTER_OTHER_COMMAND
"
fi
}
zle
-N
magic-enter
# Wrapper for the accept-line zle widget (run when pressing Enter)
# If the wrapper already exists don't redefine it
((
!
${
+functions[_magic-enter_accept-line]
}
))
||
return
0
case
"
$widgets
[accept-line]"
in
# Override the current accept-line widget, calling the old one
user:
*
)
zle
-N
_magic-enter_orig_accept-line
"
${
widgets
[accept-line]#user
:
}
"
function
_magic-enter_accept-line
()
{
magic-enter
zle _magic-enter_orig_accept-line
--
"
$@
"
}
;;
# If no user widget defined, call the original accept-line widget
builtin
)
function
_magic-enter_accept-line
()
{
magic-enter
zle .accept-line
}
;;
esac
bindkey
-M
emacs
"^M"
magic-enter
bindkey
-M
vicmd
"^M"
magic-enter
bindkey
-M
viins
"^M"
magic-enter
zle
-N
accept-line _magic-enter_accept-line
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment