clean Org file
This commit is contained in:
parent
7e29c7acbe
commit
60e323b755
3 changed files with 162 additions and 172 deletions
36
README.org
36
README.org
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
Configuration is currently done via editing the script directly or editing this file and then tangling it with Emacs (=C-c C-v t=).
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
#+begin_src sh
|
||||
# SETTINGS
|
||||
# Edit from here -->
|
||||
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
window=60 # Fading window in minutes
|
||||
|
||||
# <-- to here
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
** Requirements
|
||||
:PROPERTIES:
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
|
||||
To make sure that all requirements are fulfilled, we check them before doing anything else.
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
#+begin_src sh
|
||||
if ! command -v wget &> /dev/null
|
||||
then
|
||||
echo -ne "\e[1mwget\e[0m was not found, please install it"
|
||||
|
|
@ -63,22 +63,22 @@
|
|||
echo -ne "\e[1mxrandr\e[0m was not found, are you running the X.Org Server?"
|
||||
exit 1
|
||||
fi
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
** Local variables
|
||||
|
||||
The file containing the sunrise and sunset is stored in =/tmp=.
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
#+begin_src sh
|
||||
file=/tmp/$location
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
To make calculations easier, we scale the fading window down to seconds (=*60=) and divide it in half (=*0.5=).
|
||||
This results in a multiplication with =30=.
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
#+begin_src sh
|
||||
window=$(( $window * 30 ))
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
The following variables are also used in the script, but not initialized.
|
||||
For the sake of completion they are described here.
|
||||
|
|
@ -93,7 +93,7 @@
|
|||
The times for sunrise and sunset are fetched from [[https://weather.com/][weather.com]].
|
||||
To filter out the exact values from the response, the regular expressions from [[https://linuxconfig.org/how-to-obtain-sunrise-sunset-time-for-any-location-from-linux-command-line][this]] blog post are used.
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
#+begin_src sh
|
||||
function get_times {
|
||||
|
||||
wget -q "https://weather.com/weather/today/l/$location" -O "$file"
|
||||
|
|
@ -105,7 +105,7 @@
|
|||
sunset=$(date --date="$SUNS" +%s)
|
||||
|
||||
}
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
** Set dim value
|
||||
|
||||
|
|
@ -114,7 +114,7 @@
|
|||
|
||||
Finally the value is scaled into range [0,1].
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
#+begin_src sh
|
||||
function set_dim_value {
|
||||
|
||||
# Get current time
|
||||
|
|
@ -143,7 +143,7 @@
|
|||
value=$(echo "$value / (2.0 * $window)" | bc -l)
|
||||
|
||||
}
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
** Set display
|
||||
|
||||
|
|
@ -157,7 +157,7 @@
|
|||
| Blue | 0.8 | 1.0 |
|
||||
| Brightness | 0.8 | 1.0 |
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
#+begin_src sh
|
||||
function set_display {
|
||||
|
||||
red=1.0
|
||||
|
|
@ -171,25 +171,25 @@
|
|||
done
|
||||
|
||||
}
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
** Log
|
||||
|
||||
To make it easier to follow the script, a timestamp is prefixed on every logging output.
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
#+begin_src sh
|
||||
function log {
|
||||
log_time=$(date '+%H:%M')
|
||||
echo -ne "[\e[1m$log_time\e[0m] $1"
|
||||
}
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
** Main
|
||||
|
||||
At first the times are updated.
|
||||
Then the current display values are applied every minute.
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
#+begin_src sh
|
||||
echo -ne "\n..:: \e[1mnightlight\e[0m ::..\n\n"
|
||||
get_times
|
||||
log "got sunrise and sunset values\n"
|
||||
|
|
@ -199,4 +199,4 @@
|
|||
log "applied display values\r"
|
||||
sleep 60
|
||||
done
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
|
|
|||
10
default.nix
10
default.nix
|
|
@ -1,10 +0,0 @@
|
|||
with import <nixpkgs> {};
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "myEnv";
|
||||
buildInputs = with pkgs; [
|
||||
bc
|
||||
wget
|
||||
];
|
||||
src = null;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue