Skip to content
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

Add a shell-wrapper file #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
set -e
meson \
--prefix=$(pwd)/ide-wrapper-build \
-Dlibdir=lib \
-Dbindir=bin \
-Deditor_binary=/bin/echo \
-Deditor_args='["--some-option"]' \
-Deditor_title='Test dummy editor' \
Expand Down Expand Up @@ -49,5 +51,5 @@ jobs:

- name: Run shellcheck
run: |
shellcheck --severity=style ide-wrapper-build/bin/dummy-editor
shellcheck --severity=style ide-wrapper-build/bin/dummy-editor ide-wrapper-build/lib/ide-flatpak-wrapper/wrapper.sh ide-wrapper-build/bin/shell-wrapper

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
Loading