From d8e5a0a533e4cf8f582f97046b6b2cff2fdfe897 Mon Sep 17 00:00:00 2001 From: Penelope Gwen Date: Mon, 3 Jun 2024 20:18:15 -0600 Subject: [PATCH] Initial commit --- .gitlab-ci.yml | 65 ++++++++++++++++++++++++++++++++++ bin/sp-clipboard | 20 +++++++++++ bin/sp-global-shortcuts | 8 +++++ bin/sp-launcher | 17 +++++++++ bin/sp-lock | 16 +++++++++ bin/sp-powermenu | 18 ++++++++++ bin/sp-profiles | 45 +++++++++++++++++++++++ bin/sp-rename | 7 ++++ bin/sp-screenshot | 13 +++++++ bin/sp-shortcuts | 10 ++++++ bin/sp-wallpaper | 30 ++++++++++++++++ debian/README.Debian | 6 ++++ debian/changelog | 5 +++ debian/control | 25 +++++++++++++ debian/copyright | 60 +++++++++++++++++++++++++++++++ debian/install | 2 ++ debian/postinst | 4 +++ debian/postrm | 3 ++ debian/rules | 4 +++ debian/source/format | 1 + debian/sway-profiles-docs.docs | 1 + lib/sp-functions | 51 ++++++++++++++++++++++++++ 22 files changed, 411 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100755 bin/sp-clipboard create mode 100755 bin/sp-global-shortcuts create mode 100755 bin/sp-launcher create mode 100755 bin/sp-lock create mode 100755 bin/sp-powermenu create mode 100755 bin/sp-profiles create mode 100755 bin/sp-rename create mode 100755 bin/sp-screenshot create mode 100755 bin/sp-shortcuts create mode 100755 bin/sp-wallpaper create mode 100644 debian/README.Debian create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/install create mode 100644 debian/postinst create mode 100644 debian/postrm create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100644 debian/sway-profiles-docs.docs create mode 100755 lib/sp-functions diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..f9da97e --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,65 @@ +# Is performed before the scripts in the stages step +before_script: + - source /etc/profile + +# Defines stages which are to be executed +stages: + - build + - upload + - release + +.setup_script: &setup_scripts + - apt-get update + - apt-get -y build-dep . + - apt-get -y install dpkg-dev + +.compile: &compile + stage: compile + only: + - tags + script: + - *setup_scripts + - dpkg-buildpackage -b + - mkdir -p ./build/{release,debug} + - find ../ -name "*.deb" -not -name "*dbgsym*" -exec mv {} ./build/release/ \; + - find ../ -name "*dbgsym*.deb" -exec mv {} ./build/debug/ \; + artifacts: + paths: + - build/release/* + - build/debug/* + untracked: true + +build: + <<: *compile + stage: build + +upload: + stage: upload + dependencies: + - build + only: + - tags + script: + - find ./build/release -name "*.deb" + - debs=( $( find ./build/release -name "*.deb" ) ) + - assets="" + - for d in ${debs[@]};do + - file=$( basename ${d} ) + - url="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_TAG}/${file}" + - assets="${assets} --assets-link {\"name\":\"${file}\",\"url\":\"${url}\",\"link_type\":\"other\"} " + - "curl --header \"JOB-TOKEN: $CI_JOB_TOKEN\" --upload-file \"${d}\" \"${url}\"" + - done + - echo "ASSETS_ARG=${assets}" >> assets.env + artifacts: + reports: + dotenv: assets.env + +release: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + only: + - tags + script: + - echo "making release!" + - echo ${ASSETS_ARG} + - release-cli create --name "Release ${CI_COMMIT_TAG}" --tag-name "${CI_COMMIT_TAG}" ${ASSETS_ARG} diff --git a/bin/sp-clipboard b/bin/sp-clipboard new file mode 100755 index 0000000..f2011cd --- /dev/null +++ b/bin/sp-clipboard @@ -0,0 +1,20 @@ +#!/bin/bash + +cb_count=$(copyq count) +cb_count=10 + +wofilist="" + +for i in $(seq $cb_count);do + cb_line="$( copyq read $((${i}-1)) | tr '\n' ' ' )" + echo "${cb_line}" + if [[ "${cb_line}" == "" ]];then + cb_line=$( copyq read ? "$((${i}-1))" | head -n 1 ) + fi + wofilist="${wofilist}${setnl}${i}. ${cb_line}" + setnl="\n" +done + +selected=$( echo -e "${wofilist}" | wofi -i --dmenu -k /dev/null | cut -d. -f1) + +copyq select "$(( ${selected}-1)) " diff --git a/bin/sp-global-shortcuts b/bin/sp-global-shortcuts new file mode 100755 index 0000000..a4d20c7 --- /dev/null +++ b/bin/sp-global-shortcuts @@ -0,0 +1,8 @@ +#!/bin/bash + +source "/usr/lib/sp-functions" + +options=$( ls "${conf_dir}/global-shortcuts/" ) +op=$( echo -e "${options}" | wofi -i --dmenu | awk '{print}' ) + +"${conf_dir}/global-shortcuts/${op}" diff --git a/bin/sp-launcher b/bin/sp-launcher new file mode 100755 index 0000000..9821930 --- /dev/null +++ b/bin/sp-launcher @@ -0,0 +1,17 @@ +#!/bin/bash + +source "/usr/lib/sp-functions" +source "${conf_dir}/config" + +case $1 in + file_manager ) + launch_exec=${filemanager_cmd} + launch_arg=$( jq -r .[].home_directory "${conf_dir}/profiles/$( get_profile_id )/vars.json" ) + ;; + browser ) + launch_exec=${browser_cmd} + launch_arg=$( jq -r .[].browser_profile "${conf_dir}/profiles/$( get_profile_id )/vars.json" ) + ;; +esac + +bash -c "${launch_exec} ${launch_arg}" diff --git a/bin/sp-lock b/bin/sp-lock new file mode 100755 index 0000000..a2fb489 --- /dev/null +++ b/bin/sp-lock @@ -0,0 +1,16 @@ +#!/bin/bash + +source "/usr/lib/sp-functions" + +outputs=( $(swaymsg -t get_outputs | jq -r '.[] | {name} | "\(.name)"') ) + +for o in ${outputs[@]};do + workspace=$(swaymsg -t get_workspaces | jq -r '.[] | select(.output) | {name} | "\(.name)"') + wpno=$(cat "${cache_dir}/displays/${o}") + wp_imgpath="${conf_dir}/wallpaper/${o}/${wpno}.jpg" + sl_imgpath="${cache_dir}/lock/${o}.jpg" + convert -scale 10% -blur 0x3 -resize 500% "${wp_imgpath}" "${sl_imgpath}" + sl_args="${sl_args}--image ${o}:${sl_imgpath} " +done + +swaylock ${sl_args} diff --git a/bin/sp-powermenu b/bin/sp-powermenu new file mode 100755 index 0000000..473f182 --- /dev/null +++ b/bin/sp-powermenu @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +op=$( echo -e " Reload\n⏻ Poweroff\n Reboot\n Suspend\n🔒 Lock\n Logout" | wofi -i --dmenu -a | awk '{print tolower($2)}' ) +case $op in + poweroff) + ;& + reboot) + ;& + suspend) + systemctl $op + ;; + lock) + sp-lock + ;; + logout) + swaymsg exit + ;; +esac diff --git a/bin/sp-profiles b/bin/sp-profiles new file mode 100755 index 0000000..b8046a7 --- /dev/null +++ b/bin/sp-profiles @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +source "/usr/lib/sp-functions" + +get_profile_list + +case $1 in + next|prev) + current_profile=$(cat "${cache_dir}/active_profile") + echo ${current_profile} + ;;& + next) + new_profile=$(( ${current_profile}+1 )) + [[ "$new_profile" -eq "${p_count}" ]] && new_profile=0 + ;;& + prev) + new_profile=$(( ${current_profile}-1 )) + [[ "$new_profile" -eq "-1" ]] && new_profile=3 + ;;& + prev|next) + op=$(printf "%01d\n" ${new_profile}) + ;; + *) + for (( p="0"; p<${p_count}; p++ ));do + [[ $p -eq $(( ${p_count} - 1 )) ]] && nl="" || nl="\n" + wofilist="${wofilist}${p_icons[$p]} ${p_names[$p]}${nl}" + done + [[ -z $1 ]] && op=$( echo -e "${wofilist}" | wofi -i --dmenu --width 250 --height 320 -k /dev/null | awk '{print $2}' ) || op="${1}" + op=$(echo ${p_names[@]/$op//} | cut -d/ -f1 | wc -w | tr -d ' ') + ;; +esac + +[[ "$op" -gt "$(( $p_count - 1 ))" ]] && exit +[[ $op -eq "0" ]] && p_num="" || p_num="$op" +p_icon="${p_icons[$op]}" + +for i in {1..10};do + [[ "$i" -eq "10" ]] && k="0" || k=$i + swaymsg 'bindsym $mod+'"$k"' workspace number "'"${p_num}${i}:${p_icon}"'"' + swaymsg 'bindsym $mod+Shift+'"$k"' move container to workspace number "'"${p_num}${i}:${p_icon}"'"' +done + +moveto="${p_num}1:${p_icon}" +swaymsg 'workspace number "'"${p_num}"'"1:"'"${p_icon}"'"' +echo "${op}" > "${cache_dir}/active_profile" diff --git a/bin/sp-rename b/bin/sp-rename new file mode 100755 index 0000000..3574552 --- /dev/null +++ b/bin/sp-rename @@ -0,0 +1,7 @@ +#!/bin/bash + +source "/usr/lib/sp-functions" + +new_wsname="$( get_workspace_prefix )$(wofi -i --dmenu --height 1 --search $( get_workspace_name ))" + +swaymsg 'rename workspace "'"$( get_workspace_fullname )"'" to "'"${new_wsname}"'"' diff --git a/bin/sp-screenshot b/bin/sp-screenshot new file mode 100755 index 0000000..e58e6b3 --- /dev/null +++ b/bin/sp-screenshot @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +source "/usr/lib/sp-functions" +source "${conf_dir}/config" + +op=$( echo -e "Output\nWindow\nRegion" | wofi -i --dmenu --width 250 --height 260 | awk '{print tolower($1)}' ) + +echo "$op" + +sleep 0.5 +mkdir -p "${cache_dir}/screenshots/" +sway-screenshot -m $op --output-folder "${cache_dir}/screenshots/" +mv "${cache_dir}/screenshots/"* "${screenshot_dir}" diff --git a/bin/sp-shortcuts b/bin/sp-shortcuts new file mode 100755 index 0000000..361e69f --- /dev/null +++ b/bin/sp-shortcuts @@ -0,0 +1,10 @@ +#!/bin/bash + +source "/usr/lib/sp-functions" + +current_profile=$( get_profile_id ) + +profile_scripts=$( ls "${conf_dir}/profiles/${current_profile}/shortcuts/" ) +op=$( echo -e "${profile_scripts}" | wofi -w 2 -i --dmenu | awk '{print}' ) + +"${conf_dir}/profiles/${current_profile}/shortcuts/${op}" diff --git a/bin/sp-wallpaper b/bin/sp-wallpaper new file mode 100755 index 0000000..0551eea --- /dev/null +++ b/bin/sp-wallpaper @@ -0,0 +1,30 @@ +#!/bin/bash + +source "/usr/lib/sp-functions" + +getwpno() { + wpno=$(printf "%02d\n" $(($(echo "$1" | awk '{print $1}' | grep -o "^[1-9]*")-1)) | cut -c 1 | sed 's/[^0-9]*//g') + echo "${wpno}" | tee "${cache_dir}/displays/${2}" +} + +setbg() { + for d in ${outputs[@]};do + d_wpno=$(cat "${cache_dir}/displays/${d}") + swaymsg output "${d}" bg "${conf_dir}/wallpaper/${d}/${d_wpno}.jpg" fill + done +} + +output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | {name} | "\(.name)"') +outputs=( $(swaymsg -t get_outputs | jq -r '.[] | {name} | "\(.name)"') ) +workspace=$(swaymsg -t get_workspaces | jq -r '.[] | select(.focused) | {name} | "\(.name)"') +getwpno "${workspace}" "${output}" +setbg "${output}" "${wpno}" + +swaymsg -r -t subscribe -m '["workspace"]' | jq -rc --unbuffered 'select(.change == "focus") | .current | "\(.name) \(.output)"' | while read name output;do + wsno=$(($(echo "$name" | awk '{print $1}' | grep -o "^[1-9]*")-1)) + wpno_last=$(cat "${cache_dir}/displays/${output}") + getwpno "${name}" "${output}" + if [[ "${wpno}" -ne "${wpno_last}" ]];then + setbg "${output}" "${wpno}" + fi +done diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..c0eebc6 --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,6 @@ +sway-profiles for Debian +------------------------ + +Configuration files for sway's supporting programs + + -- Penelope Gwen , Thu, 03 Jun 2024 19:45:09 -0600 diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..3bb2aa4 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +pogmom-sway-base (0.1) unstable; urgency=medium + + * Initial release. + + -- Penelope Gwen Thu, 3 Jun 2024 19:41:19 -0600 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..c1017d6 --- /dev/null +++ b/debian/control @@ -0,0 +1,25 @@ +Source: sway-profiles +Section: X11 +Priority: optional +Maintainer: Penelope Gwen +Rules-Requires-Root: no +Build-Depends: + debhelper-compat (= 13), +Standards-Version: 4.7.0 +Homepage: https://git.pogmom.me/pogmommy/sway-profiles + +Package: sway-profiles +Architecture: all +Depends: + swaybg +Recommends: + wofi, + fonts-font-awesome +Suggests: + copyq, + sway-screenshot + + +Description: Some scripts to organize workflows on sway + A handful of useful bash scripts that let you organize + your sway workspaces into profiles diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..c86817c --- /dev/null +++ b/debian/copyright @@ -0,0 +1,60 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Source: https://git.pogmom.me/pogmommy/sway-profiles +Upstream-Name: sway-profiles +Upstream-Contact: Penelope Gwen + +Files: + * +Copyright: + 2024 Penelope Gwendolyn +License: Opinionated Queer License + PERMISSIONS + . + The creators of this Work (“The Licensor”) grant permission + to any person, group or legal entity that doesn't violate the prohibitions below (“The User”), + to do everything with this Work that would otherwise infringe their copyright or any patent claims, + subject to the following conditions: + . + OBLIGATIONS + . + The User must give appropriate credit to the Licensor, + provide a copy of this license or a (clickable, if the medium allows) link to + oql.avris.it/license/v1.1, + and indicate whether and what kind of changes were made. + The User may do so in any reasonable manner, + but not in any way that suggests the Licensor endorses the User or their use. + . + PROHIBITIONS + . + No one may use this Work for prejudiced or bigoted purposes, including but not limited to: + racism, xenophobia, queerphobia, queer exclusionism, homophobia, transphobia, enbyphobia, misogyny. + . + No one may use this Work to inflict or facilitate violence or abuse of human rights as defined in the + Universal Declaration of Human Rights. + . + No law enforcement, carceral institutions, immigration enforcement entities, military entities or military contractors + may use the Work for any reason. This also applies to any individuals employed by those entities. + . + No business entity where the ratio of pay (salaried, freelance, stocks, or other benefits) + between the highest and lowest individual in the entity is greater than 50 : 1 + may use the Work for any reason. + . + No private business run for profit with more than a thousand employees + may use the Work for any reason. + . + Unless the User has made substantial changes to the Work, + or uses it only as a part of a new work (eg. as a library, as a part of an anthology, etc.), + they are prohibited from selling the Work. + That prohibition includes processing the Work with machine learning models. + . + SANCTIONS + . + If the Licensor notifies the User that they have not complied with the rules of the license, + they can keep their license by complying within 30 days after the notice. + If they do not do so, their license ends immediately. + . + WARRANTY + . + This Work is provided “as is”, without warranty of any kind, express or implied. + The Licensor will not be liable to anyone for any damages related to the Work or this license, + under any kind of legal claim as far as the law allows. diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..51aef07 --- /dev/null +++ b/debian/install @@ -0,0 +1,2 @@ +bin/* usr/bin +lib/* usr/lib diff --git a/debian/postinst b/debian/postinst new file mode 100644 index 0000000..7ce3583 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,4 @@ +#!/bin/bash + +#mkdir -p /etc/greetd +#update-alternatives --install /etc/greetd/config.toml greetd /usr/share/greetd/pogmom/config.toml 30 --force diff --git a/debian/postrm b/debian/postrm new file mode 100644 index 0000000..3ce1856 --- /dev/null +++ b/debian/postrm @@ -0,0 +1,3 @@ +#!/bin/bash + +#update-alternatives --remove greetd /usr/share/greetd/pogmom/config.toml diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..2d33f6a --- /dev/null +++ b/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/debian/sway-profiles-docs.docs b/debian/sway-profiles-docs.docs new file mode 100644 index 0000000..86ca00f --- /dev/null +++ b/debian/sway-profiles-docs.docs @@ -0,0 +1 @@ +README.Debian diff --git a/lib/sp-functions b/lib/sp-functions new file mode 100755 index 0000000..fecd998 --- /dev/null +++ b/lib/sp-functions @@ -0,0 +1,51 @@ +#!/bin/bash + + +conf_dir="$HOME/.config/sway-profiles" +cache_dir="$HOME/.cache/sway-profiles" + +mkdir -p "${cache_dir}/"{displays,lock,screenshots} + +get_workspace_id(){ + workspace_id=$( printf "%02d\n" $( swaymsg -t get_workspaces | jq -r '.[] | select(.focused==true)|.name' | sed 's/:.*//' ) ) + echo "${workspace_id}" +} + +get_workspace_fullname(){ + workspace_fullname=$( swaymsg -t get_workspaces | jq -r '.[] | select(.focused==true)|.name' ) + echo "${workspace_fullname}" +} + +get_workspace_prefix(){ + workspace_prefix="$( grep -o '[0-9]*:[^a-zA-Z1-9]' <<< $( swaymsg -t get_workspaces | jq -r '.[] | select(.focused==true)|.name' ) )" + echo "${workspace_prefix}" +} + +get_workspace_name(){ + workspace_name=$( echo "$( get_workspace_fullname )" | sed 's/'"$( get_workspace_prefix )"'//' ) + echo "${workspace_name}" +} + +get_profile_id(){ + current_workspace=$( printf "%02d\n" $(( $( swaymsg -t get_workspaces | jq -r '.[] | select(.focused==true)|.name' | sed 's/:.*//' ) - 1 )) ) + echo "${current_workspace:0:1}" +} + +get_profile_name(){ + echo "test" +} + +get_profile_list(){ + p_icons=() + p_names=() + while read p;do + p_icons+=($( awk '{print $1}'<<<"${p}" )) + p_names+=($( awk '{print $2}'<<<"${p}" )) + done<"${conf_dir}/profile_list" + p_count="${#p_names[@]}" +} + +get_profile_icon(){ + get_profile_list + echo "${p_icons[ $( get_profile_id ) ]}" +}