diff --git a/README.md b/README.md index 53e5d53..8fb5615 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ binary and a name to install the wrapper under: Additionally, you may specify the following options: +* `-Dshell_wrapper_name` Name of an executable that launches bash with the environment set up (defaults to `shell-wrapper`). * `-Deditor_args` Command line args to append to the editor executable. * `-Deditor_title` Human readable title of the editor. This will be interpolated into the "first run template" file (more on this file later). diff --git a/editor.sh b/editor.sh new file mode 100644 index 0000000..8a1b37d --- /dev/null +++ b/editor.sh @@ -0,0 +1,26 @@ +#!@BASH@ +# shellcheck shell=bash + +set -e +shopt -s nullglob + +source "@WRAPPER_SCRIPT@" + +function exec_editor() { + exec "@EDITOR_BINARY@" @EDITOR_ARGS@ "$@" +} + +FIRST_RUN="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-first-run" +SDK_UPDATE="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-sdk-update-@SDK_VERSION@" + +if [ ! -f "${FIRST_RUN}" ]; then + touch "${FIRST_RUN}" + touch "${SDK_UPDATE}" + exec_editor "$@" "@FIRST_RUN_README@" +elif [ ! -f "${SDK_UPDATE}" ]; then + touch "${SDK_UPDATE}" + exec_editor "$@" "@SDK_UPDATE_README@" +else + exec_editor "$@" +fi + diff --git a/meson.build b/meson.build index 5c66f7e..f5ceb3d 100644 --- a/meson.build +++ b/meson.build @@ -22,6 +22,7 @@ else flatpak_id = get_option('flatpak_id') endif datadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name()) +libdir = join_paths(get_option('prefix'), get_option('libdir'), meson.project_name()) if get_option('sdk_version') == '' sdk_version_cmd = run_command('sh', '-c', '. /etc/os-release && echo $VERSION_ID', check: true) @@ -53,6 +54,7 @@ wrapper_data = configuration_data({ 'PROGRAM_NAME': get_option('program_name'), 'PYTHON_VERSION': python.language_version(), 'DEFAULT_LOGLEVEL': get_option('default_loglevel'), + 'WRAPPER_SCRIPT': join_paths(libdir, 'wrapper.sh'), }) readme_data = configuration_data({ @@ -61,12 +63,23 @@ readme_data = configuration_data({ 'SDK_VERSION': sdk_version }) -configure_file(input: 'vscode.sh', +configure_file(input: 'wrapper.sh', + output: 'wrapper.sh', + configuration: wrapper_data, + install_dir: libdir) + +configure_file(input: 'editor.sh', output: get_option('program_name'), configuration: wrapper_data, install_dir: get_option('bindir'), install_mode: 'rwxr-xr-x') +configure_file(input: 'shell_wrapper.sh', + output: get_option('shell_wrapper_name'), + configuration: wrapper_data, + install_dir: get_option('bindir'), + install_mode: 'rwxr-xr-x') + configure_file(input: first_run_template, output: first_run_filename, configuration: readme_data, diff --git a/meson_options.txt b/meson_options.txt index 867daec..aeec3bb 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,6 +2,7 @@ option('editor_binary', type: 'string') option('editor_args', type: 'array', value: []) option('editor_title', type: 'string', value: 'Visual Studio Code') option('program_name', type: 'string', value: 'code') +option('shell_wrapper_name', type: 'string', value: 'shell-wrapper') option('flatpak_id', type: 'string') option('sdk_version', type: 'string') option('first_run_template', type: 'string', value: 'first_run.txt') diff --git a/shell_wrapper.sh b/shell_wrapper.sh new file mode 100644 index 0000000..d290869 --- /dev/null +++ b/shell_wrapper.sh @@ -0,0 +1,6 @@ +#!@BASH@ +# shellcheck shell=bash + +source "@WRAPPER_SCRIPT@" + +exec "@BASH@" "$@" diff --git a/vscode.sh b/wrapper.sh old mode 100755 new mode 100644 similarity index 89% rename from vscode.sh rename to wrapper.sh index 523e0a1..77294e5 --- a/vscode.sh +++ b/wrapper.sh @@ -1,11 +1,8 @@ -#!@BASH@ # shellcheck shell=bash set -e shopt -s nullglob -FIRST_RUN="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-first-run" -SDK_UPDATE="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-sdk-update-@SDK_VERSION@" FLATPAK_IDE_LOGLEVEL="${FLATPAK_IDE_LOGLEVEL:-@DEFAULT_LOGLEVEL@}" function msg() { @@ -14,13 +11,9 @@ function msg() { fi } -function exec_vscode() { - exec "@EDITOR_BINARY@" @EDITOR_ARGS@ "$@" -} - if [ -n "${FLATPAK_IDE_ENV}" ]; then msg "Environment is already set up" - exec_vscode "$@" + return fi declare -A PATH_SUBDIRS @@ -141,14 +134,3 @@ if [ "${FLATPAK_ISOLATE_GEM}" -ne 0 ]; then fi export FLATPAK_IDE_ENV=1 - -if [ ! -f "${FIRST_RUN}" ]; then - touch "${FIRST_RUN}" - touch "${SDK_UPDATE}" - exec_vscode "$@" "@FIRST_RUN_README@" -elif [ ! -f "${SDK_UPDATE}" ]; then - touch "${SDK_UPDATE}" - exec_vscode "$@" "@SDK_UPDATE_README@" -else - exec_vscode "$@" -fi