diff --git a/example_scripts/screenshot_script b/example_scripts/screenshot_script old mode 100644 new mode 100755 index fbd463b..59cf524 --- a/example_scripts/screenshot_script +++ b/example_scripts/screenshot_script @@ -10,7 +10,20 @@ # Example: # screenshot_script "gwenview" -source "$(dirname "${BASH_SOURCE[0]}")/cb_script_header.sh" +named_pipe_send="$(mktemp -u)" +named_pipe_recv="$(mktemp -u)" +mkfifo "${named_pipe_send}" +mkfifo "${named_pipe_recv}" +nc -U "${CAGEBREAK_SOCKET}" < "${named_pipe_send}" > "${named_pipe_recv}"& +# The file descriptor 3 is set up to send commands to cagebreak and file +# descriptor 4 can be used to read events. Notice that events will pile up in +# file descriptor 4, so it is a good idea to continuously read from it or to +# clear it before starting a new transaction. +exec 3>"${named_pipe_send}" +exec 4<"${named_pipe_recv}" +# When the script exits, the os will clean up the pipe +rm "${named_pipe_recv}" +rm "${named_pipe_send}" if [[ ${#} -lt 1 ]] then diff --git a/example_scripts/show_workspace_views b/example_scripts/show_workspace_views old mode 100644 new mode 100755 index 2fd4465..33d76bc --- a/example_scripts/show_workspace_views +++ b/example_scripts/show_workspace_views @@ -1,11 +1,23 @@ #!/bin/bash # Copyright 2020 - 2024, project-repo and the cagebreak contributors # SPDX-License-Identifier: MIT - +# # This script displays the process names of the views on the current workspace. -# Start up the ipc link -source "$(dirname "${BASH_SOURCE[0]}")/cb_script_header.sh" +named_pipe_send="$(mktemp -u)" +named_pipe_recv="$(mktemp -u)" +mkfifo "${named_pipe_send}" +mkfifo "${named_pipe_recv}" +nc -U "${CAGEBREAK_SOCKET}" < "${named_pipe_send}" > "${named_pipe_recv}"& +# The file descriptor 3 is set up to send commands to cagebreak and file +# descriptor 4 can be used to read events. Notice that events will pile up in +# file descriptor 4, so it is a good idea to continuously read from it or to +# clear it before starting a new transaction. +exec 3>"${named_pipe_send}" +exec 4<"${named_pipe_recv}" +# When the script exits, the os will clean up the pipe +rm "${named_pipe_recv}" +rm "${named_pipe_send}" echo "dump" >&3 diff --git a/meson.build b/meson.build index 2ccd5a2..8b8c56d 100644 --- a/meson.build +++ b/meson.build @@ -371,6 +371,7 @@ run_target('create-artefacts', # Test Suite test('Build without warnings', find_program('test/build-w-o-warnings'), env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'devel') +test('Example script header is consistent', find_program('test/script-header'), env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'devel') test('Build without xwayland', find_program('test/build-w-o-xwayland'), env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'devel') test('Copyright and LICENSE', find_program('test/copyright-license'), args : [ cagebreak_main_file + cagebreak_source_strings + cagebreak_header_strings + fuzz_sources + fuzz_headers + fuzz_override_lib ], env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()), ''.join('MESONLICENSE=', meson.project_license())], suite: 'devel' ) test('Clang-format (formatting check)', find_program('test/clang-format'), args : [ cagebreak_main_file + cagebreak_source_strings + cagebreak_header_strings + fuzz_sources + fuzz_headers + fuzz_override_lib ], env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'devel') diff --git a/test/script-header b/test/script-header new file mode 100644 index 0000000..f172f3d --- /dev/null +++ b/test/script-header @@ -0,0 +1,17 @@ +#!/bin/bash +# Copyright 2024, project-repo and the cagebreak contributors +# SPDX-License-Identifier: MIT +# Each example script must contain the header unmodified. + +# shellcheck disable=2164 +cd "${MESONCURRENTCONFIGDIR}" + +RESULT=0 + +for file in example_scripts/* +do + # shellcheck disable=2002 + grep "$(cat test/testing-configurations/cb_script_header.sh | tail -n +3 | tr '\n' ' ' )" <(cat "$file" | tr '\n' ' ') || RESULT=1 +done + +exit $RESULT diff --git a/example_scripts/cb_script_header.sh b/test/testing-configurations/cb_script_header.sh similarity index 88% rename from example_scripts/cb_script_header.sh rename to test/testing-configurations/cb_script_header.sh index 4b17b9a..d844a0a 100644 --- a/example_scripts/cb_script_header.sh +++ b/test/testing-configurations/cb_script_header.sh @@ -1,7 +1,5 @@ -#!/bin/bash -# Copyright 2023 - 2024, project-repo and the cagebreak contributors +# Copyright 2024, project-repo and the cagebreak contributors # SPDX-License-Identifier: MIT - named_pipe_send="$(mktemp -u)" named_pipe_recv="$(mktemp -u)" mkfifo "${named_pipe_send}"