Skip to content

Ticket #4726: add mc-wrapper for fish shell #4730

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

krobelus
Copy link
Contributor

@krobelus krobelus commented Jul 5, 2025

fish shell occasionally gets bug reports from mc users, so there are definitely
some mc+fish users.

But none of them has noticed the lack of "/usr/libexec/mc/mc-wrapper.fish".

That file is supposed to define an alias that behaves like mc except that,
after mc exits, it will change fish's directory to the one last used by mc.

Users need to source this manually; if this is the behavior that most people
expect, we should make it the default (for example by shipping this function
with fish).

For now, add it to mc, which shouldn't break anyone even if fish decides to
add this as well.

Note that fish does not do word splitting, so variable expansions usually
don't need to be quoted.

Tested as follows:

$ make install
$ type mc
mc is /home/johannes/.local/bin/mc
$ source /home/johannes/.local/libexec/mc/mc.fish
$ type mc
mc is a function with definition
# Defined in /home/johannes/.local/libexec/mc/mc.fish @ line 1
function mc --description 'Visual shell for Unix-like systems - fish wrapper'
	source /home/johannes/.local/libexec/mc/mc-wrapper.fish $argv
end
mc
# navigate somewhere, press F10 to exit

Co-authored-by: Jarkko Sakkinen jarkko.sakkinen@iki.fi

Closes #4726

Signed-off-by: Johannes Altmanninger aclopte@gmail.com

@github-actions github-actions bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels Jul 5, 2025
@github-actions github-actions bot added this to the Future Releases milestone Jul 5, 2025
@krobelus
Copy link
Contributor Author

krobelus commented Jul 5, 2025

I didn't notice the build was broken because I had a stale contrib/Makefile locally.
Will fix. Normally I'd run git clean -dxn but I have some files I want to keep..
(make clean and make distclean still leave behind some stuff..)

@mc-worker mc-worker added area: core Issues not related to a specific subsystem and removed needs triage Needs triage by maintainers labels Jul 5, 2025
@zyv zyv modified the milestones: Future Releases, 4.8.34 Jul 9, 2025
zyv and others added 3 commits July 9, 2025 07:54
fish shell occasionally gets bug reports from mc users, so there are definitely
some mc+fish users, but none of them has noticed the lack of
"/usr/libexec/mc/mc-wrapper.fish".

That file is supposed to define an alias that behaves like mc except that,
after mc exits, it will change fish's directory to the one last used by mc.

Users need to source this manually; if this is the behavior that most people
expect, we should make it the default (for example by shipping this function
with fish).

For now, add it to mc, which shouldn't break anyone even if fish decides to
add this as well.

Note that fish does not do word splitting, so variable expansions usually
don't need to be quoted.

Tested as follows:

	$ make install
	$ type mc
	mc is /home/johannes/.local/bin/mc
	$ source /home/johannes/.local/libexec/mc/mc.fish
	$ type mc
	mc is a function with definition
	# Defined in /home/johannes/.local/libexec/mc/mc.fish @ line 1
	function mc --description 'Visual shell for Unix-like systems - fish wrapper'
		source /home/johannes/.local/libexec/mc/mc-wrapper.fish $argv
	end
	mc
	# navigate somewhere, press F10 to exit

Closes MidnightCommander#4726.

Co-authored-by: Jarkko Sakkinen <jarkko.sakkinen@iki.fi>
Signed-off-by: Johannes Altmanninger <aclopte@gmail.com>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
This was missed in 76555ad (man: much use of directory macros, 2021-12-08).

Signed-off-by: Johannes Altmanninger <aclopte@gmail.com>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Johannes Altmanninger <aclopte@gmail.com>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
Copy link
Member

@zyv zyv left a comment

Choose a reason for hiding this comment

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

In light of the discussion in #4726, I reverted my changes that silenced mc return code. I also added a comment to the wrappers to that effect.

@zyv zyv requested a review from mc-worker July 9, 2025 05:58
end

# Propagate mc exit code outside the wrapper
@bindir@/mc -P "$MC_PWD_FILE" $argv
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will not actually propagate the exit code beyond line 13.
If we do want to propagate it (which seems like a good idea),
then we should be doing something like this (untested)
but probably for all shells

diff --git a/contrib/mc-wrapper.sh.in b/contrib/mc-wrapper.sh.in
index 399b38a892..1a8200b5de 100644
--- a/contrib/mc-wrapper.sh.in
+++ b/contrib/mc-wrapper.sh.in
@@ -6,7 +6,8 @@
 	MC_PWD_FILE="`mktemp "/tmp/mc.pwd.XXXXXX"`"
 fi
 
-@bindir@/mc -P "$MC_PWD_FILE" "$@" || true
+MC_STATUS=0
+@bindir@/mc -P "$MC_PWD_FILE" "$@" || MC_STATUS=$?
 
 if test -r "$MC_PWD_FILE"; then
 	MC_PWD="`cat "$MC_PWD_FILE"`"
@@ -18,3 +19,4 @@
 
 rm -f "$MC_PWD_FILE"
 unset MC_PWD_FILE
+eval "unset MC_STATUS; exit $MC_STATUS"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the comment was written assuming set -e, which is not the usual behavior, and even in that case we want to clean up.. though that's an edge case of an edge case

mc.csh.in \
mc.sh.in \
mc-wrapper.csh.in \
mc-wrapper.fish.in \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW I intentionally did not include the fish lines in this commit because they belong in the commit that adds the referenced fish files.
Of course the advantage from the separate commit is fairly small here so both could be combined into a single commit also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues not related to a specific subsystem prio: medium Has the potential to affect progress
Development

Successfully merging this pull request may close these issues.

3 participants