Skip to content

Commit

Permalink
Add the shell-wrapper file
Browse files Browse the repository at this point in the history
  • Loading branch information
blt-r committed Nov 12, 2023
1 parent e42aba9 commit e39f7bd
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
26 changes: 26 additions & 0 deletions editor.sh
Original file line number Diff line number Diff line change
@@ -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

15 changes: 14 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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({
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 6 additions & 0 deletions shell_wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!@BASH@
# shellcheck shell=bash

source "@WRAPPER_SCRIPT@"

exec "@BASH@" "$@"
20 changes: 1 addition & 19 deletions vscode.sh → wrapper.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit e39f7bd

Please sign in to comment.