dtfscripts: Major refactor with more modular service startup
This commit is contained in:
53
.config/dtfscripts/services/common.bash
Executable file
53
.config/dtfscripts/services/common.bash
Executable file
@@ -0,0 +1,53 @@
|
||||
#! /usr/bin/env bash
|
||||
#
|
||||
# wmstartup service common functions
|
||||
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
#
|
||||
|
||||
service_name="unnamed_service"
|
||||
service_process="true"
|
||||
|
||||
function svc_log() {
|
||||
if [ -z ${1+x} ]; then return 1; fi
|
||||
dtf_log "$service_name: $1"
|
||||
}
|
||||
|
||||
function prestart() {
|
||||
if ! which $service_process > /dev/null 2>&1; then
|
||||
svc_log "Could not find process"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
function start() {
|
||||
if ! prestart; then
|
||||
svc_log "Failed pre-start checks"
|
||||
return 1
|
||||
fi
|
||||
svc_log "Starting"
|
||||
$service_process > /dev/null 2>&1 &
|
||||
return 0
|
||||
}
|
||||
|
||||
function stop() {
|
||||
svc_log "Stopping"
|
||||
killall $service_process &
|
||||
for i in {1..100}; do
|
||||
if ! isup; then break; fi
|
||||
sleep 0.01
|
||||
if (( $i > 99 )); then
|
||||
svc_log "Stopping with prejudice"
|
||||
killall -9 $service_process
|
||||
fi
|
||||
done
|
||||
return $?
|
||||
}
|
||||
|
||||
function isup() {
|
||||
pgrep "$service_process" > /dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
|
23
.config/dtfscripts/services/compton.dtf
Executable file
23
.config/dtfscripts/services/compton.dtf
Executable file
@@ -0,0 +1,23 @@
|
||||
#! /usr/bin/env bash
|
||||
#
|
||||
# Simple wmstartup service
|
||||
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
#
|
||||
|
||||
source $DTF_SERVICES_DIR/common.bash
|
||||
service_name="Compton"
|
||||
service_process="compton"
|
||||
|
||||
function start() {
|
||||
if [[ "$HOST" == "vm-*" ]]; then
|
||||
svc_log "Will not start: in a VM"
|
||||
return 0
|
||||
else
|
||||
svc_log "Starting"
|
||||
$service_process > /dev/null 2>&1 &
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
24
.config/dtfscripts/services/conky.dtf
Executable file
24
.config/dtfscripts/services/conky.dtf
Executable file
@@ -0,0 +1,24 @@
|
||||
#! /usr/bin/env bash
|
||||
#
|
||||
# Simple wmstartup service
|
||||
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
#
|
||||
|
||||
source $DTF_SERVICES_DIR/common.bash
|
||||
service_name="Conky"
|
||||
service_process="conky"
|
||||
|
||||
function start() {
|
||||
if ! prestart; then
|
||||
svc_log "Failed pre-start checks"
|
||||
return 1
|
||||
fi
|
||||
for file in $XDG_CONFIG_HOME/conky/*.conf; do
|
||||
svc_log "Starting with config $file"
|
||||
conky -c $file > /dev/null 2>&1 &
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
12
.config/dtfscripts/services/dunst.dtf
Executable file
12
.config/dtfscripts/services/dunst.dtf
Executable file
@@ -0,0 +1,12 @@
|
||||
#! /usr/bin/env bash
|
||||
#
|
||||
# Simple wmstartup service
|
||||
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
#
|
||||
|
||||
source $DTF_SERVICES_DIR/common.bash
|
||||
service_name="Dunst"
|
||||
service_process="dunst"
|
||||
|
16
.config/dtfscripts/services/kill_krunner.dtf
Executable file
16
.config/dtfscripts/services/kill_krunner.dtf
Executable file
@@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env bash
|
||||
#
|
||||
# Simple wmstartup service
|
||||
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
#
|
||||
|
||||
source $DTF_SERVICES_DIR/common.bash
|
||||
service_name="Krunner"
|
||||
service_process="krunner"
|
||||
|
||||
function start() {
|
||||
return 0
|
||||
}
|
||||
|
12
.config/dtfscripts/services/plasmashell.dtf
Executable file
12
.config/dtfscripts/services/plasmashell.dtf
Executable file
@@ -0,0 +1,12 @@
|
||||
#! /usr/bin/env bash
|
||||
#
|
||||
# Simple wmstartup service
|
||||
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
#
|
||||
|
||||
source $DTF_SERVICES_DIR/common.bash
|
||||
service_name="Plasma"
|
||||
service_process="plasmashell"
|
||||
|
35
.config/dtfscripts/services/polybar.dtf
Executable file
35
.config/dtfscripts/services/polybar.dtf
Executable file
@@ -0,0 +1,35 @@
|
||||
#! /usr/bin/env bash
|
||||
#
|
||||
# Simple wmstartup service
|
||||
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
#
|
||||
|
||||
source $DTF_SERVICES_DIR/common.bash
|
||||
service_name="Polybar"
|
||||
service_process="polybar"
|
||||
|
||||
function start() {
|
||||
if ! prestart; then
|
||||
svc_log "Failed pre-start checks"
|
||||
return 1
|
||||
fi
|
||||
export PB_MONITOR=$(xrandr -q | awk '/primary/{print $1}')
|
||||
svc_log "Starting primary on monitor $PB_MONITOR"
|
||||
polybar -r primary& > /dev/null 2>&1
|
||||
polybar -r primary-2& > /dev/null 2>&1
|
||||
|
||||
export secondary_monitors=$(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}')
|
||||
if [[ "$secondary_monitors" == "" ]]; then
|
||||
return 0
|
||||
fi
|
||||
for monitor in $secondary monitors; do
|
||||
svc_log "Starting secondary on monitor $monitor"
|
||||
PB_MONITOR=$monitor
|
||||
polybar -r secondary& > /dev/null 2>&1
|
||||
polybar -r secondary-2& > /dev/null 2>&1
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
23
.config/dtfscripts/services/sxhkd.dtf
Executable file
23
.config/dtfscripts/services/sxhkd.dtf
Executable file
@@ -0,0 +1,23 @@
|
||||
#! /usr/bin/env bash
|
||||
#
|
||||
# Simple wmstartup service
|
||||
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
#
|
||||
|
||||
source $DTF_SERVICES_DIR/common.bash
|
||||
service_name="sxhkd"
|
||||
service_process="sxhkd"
|
||||
|
||||
function prestart() {
|
||||
if ! which $service_process > /dev/null 2>&1; then
|
||||
svc_log "Could not find process"
|
||||
fi
|
||||
if ! pgrep bspwm > /dev/null 2>&1; then
|
||||
svc_log "Not under bspwm"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user