Last active
September 14, 2026 18:26
-
-
Save MeganerdNL/055d09bf34a5ed964c87f1057d03362a to your computer and use it in GitHub Desktop.
mc-wrapper script to exit in the last active directory of Midnight Commander for the bash shell (homebrew version)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Place somewhere: for example ~/bin/mc-wrapper-homebrew-bash.sh | |
| ## Paste the following in ~/.bashrc: alias mc='. ~/bin/mc-wrapper-homebrew-bash.sh' | |
| if test -n "$MC_TMPDIR"; then | |
| MC_PWD_FILE="`mktemp "${MC_TMPDIR}/mc.pwd.XXXXXX"`" | |
| elif test -n "$TMPDIR"; then | |
| MC_PWD_FILE="`mktemp "${TMPDIR}/mc.pwd.XXXXXX"`" | |
| else | |
| MC_PWD_FILE="`mktemp "/tmp/mc.pwd.XXXXXX"`" | |
| fi | |
| mcversion=$(ls -v /var/home/linuxbrew/.linuxbrew/Cellar/midnight-commander | tail -1) | |
| /home/linuxbrew/.linuxbrew/Cellar/midnight-commander/$mcversion/bin/mc -P "$MC_PWD_FILE" "$@" | |
| if test -r "$MC_PWD_FILE"; then | |
| MC_PWD="`cat "$MC_PWD_FILE"`" | |
| if test -n "$MC_PWD" && test "$MC_PWD" != "$PWD" && test -d "$MC_PWD"; then | |
| cd "$MC_PWD" || true | |
| fi | |
| unset MC_PWD | |
| fi | |
| rm -f "$MC_PWD_FILE" | |
| unset MC_PWD_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment