Skip to content
Open
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
56 changes: 33 additions & 23 deletions screenz
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#!/bin/bash

# { FONCTION TO CHECK THE INITIALIZATION } #
# Set global path variable
# Use XDG standard if in use
if [[ -d "${XDG_CONFIG_HOME}" ]]; then
screenz-config="${XDG_CONFIG_HOME}/screenz"
else
screenz-config="${HOME}/.config/screenz"
fi
mkdir -p "${screenz-config}"

# { FUNCTION TO CHECK THE INITIALIZATION } #

function check_init() {
count=0
Expand All @@ -14,9 +23,9 @@ function check_init() {
exit 84
fi
((count++))
done < ~/.screenz
done < "${screenz-config}/parameters"
if [[ count -ne 2 ]]; then
rm -f ~/.screenz
rm -f "${screenz-config}/parameters"
echo "Error config file make a 'screenz -i'."
exit 84
fi
Expand All @@ -43,8 +52,8 @@ function help() {
echo -e "\tOn error, screenz return 84."
echo -e ""
echo -e "\e[1mOTHER\e[0m"
echo -e "\tThis application generates a hidden file to run."
echo -e "\t\t'.screenz' is a hidden file that contains your parameters (do not modify)."
echo -e "\tThis application generates a parameter file to run."
echo -e "\t\tparameters are generated in the ${screenz-config}/parameters file, it is recommended that you do not modify this file."
echo -e ""
}
# {FUNCTION TO INITIALIZED THE PROGRAM (-I)} #
Expand All @@ -54,11 +63,11 @@ function init() {
printf "Where is the position of your output relative to your computer? (left-of/right-of/above/below): "
read answer
if [[ $answer == "left-of" ]] || [[ $answer == "right-of" ]] || [[ $answer == "above" ]] || [[ $answer == "below" ]]; then
if [[ ! -e ~/.screenz ]]; then
echo -e "\n" >> ~/.screenz
if [[ ! -e "${screenz-config}/parameters" ]]; then
echo -e "\n" >> "${screenz-config}/parameters"
fi
sed -i '2d' ~/.screenz
sed -i 1a"$answer" ~/.screenz
sed -i '2d' "${screenz-config}/parameters"
sed -i 1a"$answer" "${screenz-config}/parameters"
break
else
echo "Invalid answer"
Expand All @@ -69,7 +78,7 @@ function init() {
printf "You want to add 'screenz' in your system command ? (y/N): "
read answer
if [[ $answer == "y" ]]; then
sudo cp -f screenz /usr/bin/
sudo cp -i screenz /usr/bin/
break
elif [[ $answer == "N" ]]; then
break
Expand All @@ -86,18 +95,18 @@ function auto () {
count=0
countw=0
defaultscrenz="-1"
rm -f ~/.temp
rm -f /tmp/screenz-tmp
while [[ 1 ]]; do
xrandr --current >> ~/.temp
if [[ -e ~/.screenz ]]; then
xrandr --current >> /tmp/screenz-tmp
if [[ -e "${screenz-config}/parameters" ]]; then
while read lines || [[ -n "$lines" ]]; do
if [[ $countw == 0 ]] && [[ -n $lines ]]; then
screenz=$lines
elif [[ $countw == 1 ]] && [[ -n $lines ]]; then
position=$lines
fi
((countw++))
done < ~/.screenz
done < "${screenz-config}/parameters"
countw=0
if [[ $count < 1 ]] && [[ $screenz != "" ]] && [[ $screenz != "\0" ]]; then
((count++))
Expand All @@ -109,8 +118,8 @@ function auto () {
defaultscrenz=${tab[0]}
((nb++))
elif [[ ${tab[0]} != $defaultscrenz ]] && [[ ${tab[1]} == "connected" ]] && [[ ${tab[0]} != $screenz ]] && [[ $nb == 1 ]]; then
sed -i '1d' ~/.screenz
sed -i 1i"${tab[0]}" ~/.screenz
sed -i '1d' "${screenz-config}/parameters"
sed -i 1i"${tab[0]}" "${screenz-config}/parameters"
xrandr --output ${tab[0]} --auto --$position $defaultscrenz
if [[ ! -e /usr/bin/wzpaper ]]; then
killall wzpaper > /dev/null 2>&1
Expand All @@ -119,13 +128,13 @@ function auto () {
count=0
elif [[ ${tab[0]} == "$screenz" ]] && [[ ${tab[1]} == "disconnected" ]]; then
xrandr --output ${tab[0]} --off
sed -i '1d' ~/.screenz
sed -i 1i'\ \' ~/.screenz
sed -i '1d' "${screenz-config}/parameters"
sed -i 1i'\ \' "${screenz-config}/parameters"
screenz="\0"
count=0
fi
done < ~/.temp
rm -f ~/.temp
done < /tmp/screenz-tmp
rm -f /tmp/screenz-tmp
sleep 1s
done
}
Expand Down Expand Up @@ -153,12 +162,12 @@ function choise() {
echo -e "no output connected."
exit 84
fi
done < ~/.temp
done < /tmp/screenz-tmp
if [[ $nb == 1 ]]; then
echo -e "no output connected."
exit 84
fi
rm -f ~/.temp
rm -f /tmp/screenz-tmp
while [[ 1 ]]; do
printf "\nwhich output do you want ? : "
read answer
Expand Down Expand Up @@ -189,7 +198,7 @@ function choise() {
}
# {SWITCH CASE} #

xrandr --current >> ~/.temp
xrandr --current >> /tmp/screenz-tmp
IFS=" "

case $1 in
Expand Down Expand Up @@ -219,4 +228,5 @@ case $1 in
exit 84
;;
esac
unset screenz-config
exit 0