filesystem: Improve the shell script.
This script can now also be used for executing commands with custom
handling for better MSYS2 integration. The following commands are
currently supported and more can be added:
* Windows Explorer, for proper backslash path conversion.
* Windows command prompt, for properly executing under winpty.
* Programs under /mingw32 and /mingw64, for the same reason.
This commit is contained in:
@@ -60,7 +60,7 @@ sha256sums=('6d651f6b0b2d173961a3fa21acd9d44c783ed9cd73a031687698c8b9ed1f6dee'
|
||||
'0a3a3b131ace34f11f428118dfe81b34da148e29b6bea3b027d79bebd47141a7'
|
||||
'020d0619a6af9a4d6e1068cb77f2789bcf470380426214e90177f5596d651835'
|
||||
'756df34c5b28478a81331785de0f56438bb652cf5f29029a9db2d83281361340'
|
||||
'4da1901fc060198cb1261d1f855b4f76042a50272815726d8e0518afdcc4689f'
|
||||
'dbf1fd2d38a89346545ebaa0969ab8bf8bf588db854b5f23690f9eefd87afc8e'
|
||||
'f63241cc56aa7b7ec6962d19991d211b4e1641b78ba5226835118ab493830a8b'
|
||||
'e96c1f54ffff792e738aa032815c82c30821b0683806e5ed0ba2a759db2fd494'
|
||||
'95105051d31ecbe4ace262a4496ec1055bdd14d61b7d475a771b56fe15f8ccd9'
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "${BASH_SOURCE}" = "${0}" || ! "${1}" =~ ^(mingw(32|64)|msys)$ ]]; then tee <<done
|
||||
if [[ -z "${1}" || "${1}" =~ ^(--help|-h)$ ]]; then tee <<done
|
||||
|
||||
MSYS2 Shell Switcher 2016.5.1
|
||||
The MSYS2 Shell Manager 2016.5.1
|
||||
Copyright (C) 2016 Renato Silva
|
||||
Licensed under public domain
|
||||
|
||||
This script switches between shells without restarting MSYS2. This is done
|
||||
by setting the MSYSTEM variable and sourcing /etc/profile, as well as
|
||||
~/.bashrc, for interactive shells.
|
||||
Usage: source $(basename "${0}") mingw32|mingw64|msys
|
||||
|
||||
Usage: source $(basename "${0}") mingw32|mingw64|msys
|
||||
Switch between shells without restarting MSYS2. This is done by setting the
|
||||
MSYSTEM variable and sourcing /etc/profile. For interactive shells,
|
||||
~/.bashrc is also sourced.
|
||||
|
||||
Usage: $(basename "${0}") COMMAND [ARGUMENTS]...
|
||||
|
||||
Execute commands with better MSYS2 integration, currently:
|
||||
- Convert Windows Explorer arguments to backslash paths.
|
||||
- Use winpty for executing Windows command prompt and commands from /mingw32
|
||||
and /mingw64, so they work better under MinTTY and similar terminals.
|
||||
|
||||
done
|
||||
if [[ "${BASH_SOURCE}" = "${0}" ]]
|
||||
@@ -19,9 +26,48 @@ done
|
||||
fi
|
||||
fi
|
||||
|
||||
_current_directory="$(pwd)"
|
||||
export MSYSTEM="${1^^}"
|
||||
source /etc/profile
|
||||
[[ "${-}" = *i* ]] && source ~/.bashrc
|
||||
cd "${_current_directory}"
|
||||
unset _current_directory
|
||||
if [[ "${BASH_SOURCE}" != "${0}" && ! "${1}" =~ ^(mingw32|mingw64|msys)$ ]]; then
|
||||
echo "Unrecognized shell type ${1}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ "${BASH_SOURCE}" = "${0}" && "${1}" =~ ^(mingw32|mingw64|msys)$ ]]; then
|
||||
echo "Cannot switch to ${1} shell without sourcing"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${BASH_SOURCE}" = "${0}" && -z "$(type -t "${1}")" ]]; then
|
||||
echo "Could not find command ${1}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${BASH_SOURCE}" != "${0}" ]]; then
|
||||
_current_directory="$(pwd)"
|
||||
export MSYSTEM="${1^^}"
|
||||
source /etc/profile
|
||||
[[ "${-}" = *i* ]] && source ~/.bashrc
|
||||
cd "${_current_directory}"
|
||||
unset _current_directory
|
||||
return 0
|
||||
else
|
||||
command="$(type -P "${1}")"
|
||||
command="${command,,}"
|
||||
command="${command%.exe}"
|
||||
explorer="$(cygpath --windir)/explorer"
|
||||
explorer="${explorer,,}"
|
||||
cmd="$(cygpath --windir)/system32/cmd"
|
||||
cmd="${cmd,,}"
|
||||
case "${command}" in
|
||||
"${explorer}") _arguments=()
|
||||
for _argument in "${@:2}"; do
|
||||
_arguments+=("$(cygpath --windows "${_argument}")")
|
||||
done
|
||||
"${1}" "${_arguments[@]}" ;;
|
||||
"${cmd}") winpty "${@}" || exit ;;
|
||||
/usr/bin/cmd) winpty "${@}" || exit ;;
|
||||
/mingw32/*) winpty "${@}" || exit ;;
|
||||
/mingw64/*) winpty "${@}" || exit ;;
|
||||
*) "${@}" || exit ;;
|
||||
esac
|
||||
exit 0
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user