mirror of
https://github.com/SqrtMinusOne/dotfiles.git
synced 2025-12-10 11:13:04 +03:00
feat(console): cleanup scripts, move autocommit to console
This commit is contained in:
parent
349b0fd5dd
commit
6070c4bca9
13 changed files with 216 additions and 186 deletions
2
.config/cron/autocommit.guile
Normal file
2
.config/cron/autocommit.guile
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(job "0 * * * *" "autocommit ~/Documents/org-mode")
|
||||
(job "0,15,30,45 * * * *" "autocommit ~/.password-store")
|
||||
107
Console.org
107
Console.org
|
|
@ -793,7 +793,114 @@ key_bindings:
|
|||
| Note | Description |
|
||||
|------+-----------------|
|
||||
| TODO | package fselect |
|
||||
* Misc scripts
|
||||
** =nt= - exec command with a finished notification
|
||||
Usage:
|
||||
|
||||
#+begin_example
|
||||
nt <command>
|
||||
#+end_example
|
||||
|
||||
#+begin_src sh :tangle ~/bin/scripts/nt
|
||||
command="$@"
|
||||
if [ ! -z "$command" ]; then
|
||||
start_time="$(date -u +%s)"
|
||||
$command
|
||||
end_time="$(date -u +%s)"
|
||||
elapsed="$(($end_time-$start_time))"
|
||||
notify-send "Terminal" "Command\n$command\nexecuted in $elapsed seconds"
|
||||
else
|
||||
notify-send "Terminal" "Command execution complete"
|
||||
fi
|
||||
#+end_src
|
||||
** =autocommmit=
|
||||
A script to autocommit files in a repository. I use it to sync my org directory and password store. I guess it's not how git is intended to be used, but it works for me.
|
||||
|
||||
Usage:
|
||||
#+begin_example
|
||||
autocommit <repository> [-F]
|
||||
#+end_example
|
||||
|
||||
Environment:
|
||||
| Variable | Description | Default value |
|
||||
|---------------+-----------------+---------------|
|
||||
| =TIMEOUT_MIN= | Default timeout | 60 |
|
||||
|
||||
Here's more or less what the script is doing:
|
||||
- If there is a merge conflict, notify
|
||||
- If there are changed files in the last =TIMEOUT_MIN= minutes, commit
|
||||
- Fetch
|
||||
- If there are were changes in the last =TTMEOUT_MIN=, merge (usually the merge has to be fast-forward)
|
||||
- If fetch was successful & merge was successful or delayed because of changes in the last =TIMEOUT_MIN=, push
|
||||
- Send a notification about the events above
|
||||
- Send a separate notification if there is a merge conflict
|
||||
|
||||
#+begin_src bash :tangle ~/bin/scripts/autocommit
|
||||
TIMEOUT_MIN=${TIMEOUT_MIN:-60}
|
||||
|
||||
export DISPLAY=:0
|
||||
cd "$1"
|
||||
|
||||
TIMESTAMP=$(date +%s)
|
||||
LAST_COMMIT_TIMESTAMP=$(git log -1 --format="%at" | xargs -I{} date -d @{} +%s)
|
||||
RECENTLY_CHANGED_NUM=$(find . -not -path '*/\.*' -mmin -$TIMEOUT_MIN | wc -l)
|
||||
CHANGED_NUM=$(git status --porcelain | wc -l)
|
||||
COMMITED="No"
|
||||
PUSHED="No"
|
||||
FETCHED="No"
|
||||
MERGED="No"
|
||||
|
||||
if [[ $(git ls-files -u | wc -l) -gt 0 ]]; then
|
||||
notify-send -u critical "Autocommit $(pwd)" "Merge conflict!"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ ($RECENTLY_CHANGED_NUM -eq 0 || $2 = "-F") && $CHANGED_NUM -gt 0 ]]; then
|
||||
read -r -d '' MESSAGE << EOM
|
||||
Autocommit $(date -Iminutes)
|
||||
|
||||
Hostname: $(hostname)
|
||||
EOM
|
||||
git add -A
|
||||
git commit -m "$MESSAGE"
|
||||
COMMITED="Yes"
|
||||
fi
|
||||
|
||||
NEED_TO_PUSH=$(git log origin/master..HEAD | wc -l)
|
||||
|
||||
git fetch && FETCHED="Yes" || FETCHED="No"
|
||||
if [[ $RECENTLY_CHANGED_NUM -gt 0 && $2 != '-F' ]]; then
|
||||
MERGED="Waiting"
|
||||
fi
|
||||
|
||||
if [[ ($RECENTLY_CHANGED_NUM -eq 0 || $2 = "-F") && $FETCHED = "Yes" ]]; then
|
||||
MERGE_OUT=$(git merge origin/master) && MERGED="Yes" || MERGED="No"
|
||||
fi
|
||||
|
||||
if [[ $NEED_TO_PUSH -gt 0 && ($MERGED = "Yes" || $MERGED = "Waiting") ]]; then
|
||||
git push origin && PUSHED="Yes" || PUSHED="No"
|
||||
fi
|
||||
|
||||
if [[ $PUSHED = "Yes" || $COMMITED = "Yes" || ($MERGED = "Yes" && $MERGE_OUT != "Already up to date.")]]; then
|
||||
read -r -d '' NOTIFICATION << EOM
|
||||
Commited: $COMMITED
|
||||
Fetched: $FETCHED
|
||||
Merged: $MERGED
|
||||
Pushed: $PUSHED
|
||||
EOM
|
||||
notify-send "Autocommit $(pwd)" "$NOTIFICATION"
|
||||
fi
|
||||
|
||||
if [[ $(git ls-files -u | wc -l) -gt 0 ]]; then
|
||||
notify-send -u critical "Autocommit $(pwd)" "Merge conflict!"
|
||||
fi
|
||||
#+end_src
|
||||
|
||||
=mcron= job:
|
||||
#+begin_src scheme :tangle ~/.config/cron/autocommit.guile
|
||||
(job "0 * * * *" "autocommit ~/Documents/org-mode")
|
||||
(job "0,15,30,45 * * * *" "autocommit ~/.password-store")
|
||||
#+end_src
|
||||
* Guix settings
|
||||
#+NAME: packages
|
||||
#+begin_src emacs-lisp :tangle no
|
||||
|
|
|
|||
48
Emacs.org
48
Emacs.org
|
|
@ -2455,54 +2455,6 @@ There are some problems with org roam v2, so I disabled it as of now. I will pro
|
|||
:config
|
||||
(org-roam-bibtex-mode))
|
||||
#+end_src
|
||||
*** autocommit
|
||||
A script to autocommit files in my org directory.
|
||||
|
||||
- If there are changed files and no files were changed over the last 60 minutes, commit.
|
||||
- If there is an unpushed commit, push
|
||||
- If either of these happened, make a notification
|
||||
|
||||
#+begin_src bash :tangle ~/Documents/org-mode/commit.sh
|
||||
TIMEOUT_MIN=60
|
||||
|
||||
export DISPLAY=:0
|
||||
cd $HOME/Documents/org-mode
|
||||
|
||||
TIMESTAMP=$(date +%s)
|
||||
LAST_COMMIT_TIMESTAMP=$(git log -1 --format="%at" | xargs -I{} date -d @{} +%s)
|
||||
RECENTLY_CHANGED_NUM=$(find . -not -path '*/\.*' -mmin -$TIMEOUT_MIN | wc -l)
|
||||
CHANGED_NUM=$(git diff-index --name-only HEAD -- | wc -l)
|
||||
COMMITED="No"
|
||||
PUSHED="No"
|
||||
|
||||
if [[ ($RECENTLY_CHANGED_NUM -eq 0 || $1 = "-F") && $CHANGED_NUM -gt 0 ]]; then
|
||||
read -r -d '' MESSAGE << EOM
|
||||
Autocommit $(date -Iminutes)
|
||||
|
||||
Hostname: $(hostname)
|
||||
EOM
|
||||
git add *
|
||||
git commit -m "$MESSAGE"
|
||||
COMMITED="Yes"
|
||||
fi
|
||||
|
||||
if [ $(git log origin/master..HEAD | wc -l) -gt 0 ]; then
|
||||
git push && PUSHED="Yes" || PUSHED="No"
|
||||
fi
|
||||
|
||||
if [[ $PUSHED = "Yes" || $COMMITED = "Yes" ]]; then
|
||||
read -r -d '' NOTIFICATION << EOM
|
||||
Commited: $COMMITED
|
||||
Pushed: $PUSHED
|
||||
EOM
|
||||
notify-send "Org mode sync" "$NOTIFICATION"
|
||||
fi
|
||||
#+end_src
|
||||
|
||||
Cron job:
|
||||
#+begin_src scheme :tangle ~/.config/cron/org-mode.guile
|
||||
(job "0 * * * *" "~/Documents/org-mode/commit.sh")
|
||||
#+end_src
|
||||
** UI
|
||||
*** OFF (OFF) Instant equations preview
|
||||
Instant math previews for org mode.
|
||||
|
|
|
|||
79
Guix.org
79
Guix.org
|
|
@ -610,6 +610,46 @@ Third, by default it tries to create envronments in =/gnu/store=. I think it's e
|
|||
mkdir -p ~/.conda/envs
|
||||
conda create -p ~/.conda/envs/test
|
||||
#+end_src
|
||||
|
||||
Finally, I also want to have an ability to use global npm. Some settings for that are located in [[file:Console::*npm][Console.org]]. Here we want to unset =NPM_CONFIG_USERCONFIG= if there is npm available in the environment.
|
||||
|
||||
So here is a script to set up conda hooks:
|
||||
#+begin_src bash :tangle ~/bin/scripts/setup-conda-npm
|
||||
# Get writable conda envs with npm & without
|
||||
readarray -t CONDA_ENVS_ALL <<< $(conda env list --json | jq '.envs[]')
|
||||
CONDA_ENVS_NPM=()
|
||||
CONDA_ENVS_NO_NPM=()
|
||||
for env in "${CONDA_ENVS_ALL[@]}"; do
|
||||
env="${env:1:${#env}-2}"
|
||||
if [ -w "$env" ]; then
|
||||
if [ -f "$env/bin/npm" ]; then
|
||||
CONDA_ENVS_NPM+=($env)
|
||||
else
|
||||
CONDA_ENVS_NO_NPM+=($env)
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
for env in "${CONDA_ENVS_NPM[@]}"; do
|
||||
echo "Found npm in $env"
|
||||
mkdir -p "$env/etc/conda/activate.d"
|
||||
mkdir -p "$env/etc/conda/deactivate.d"
|
||||
|
||||
echo "unset NPM_CONFIG_USERCONFIG" > "$env/etc/conda/activate.d/conda.sh"
|
||||
echo "set -e NPM_CONFIG_USERCONFIG" > "$env/etc/conda/activate.d/conda.fish"
|
||||
echo "export NPM_CONFIG_USERCONFIG=$HOME/._npmrc" > "$env/etc/conda/deactivate.d/conda.sh"
|
||||
echo "export NPM_CONFIG_USERCONFIG=$HOME/._npmrc" > "$env/etc/conda/deactivate.d/conda.fish"
|
||||
done
|
||||
|
||||
for env in "${CONDA_ENVS_NO_NPM}"; do
|
||||
echo "Did not found npm in $env"
|
||||
rm -rf "$env/etc/conda/activate.d/conda.sh" || true
|
||||
rm -rf "$env/etc/conda/activate.d/conda.fish" || true
|
||||
rm -rf "$env/etc/conda/deactivate.d/conda.sh" || true
|
||||
rm -rf "$env/etc/conda/deactivate.d/conda.fish" || true
|
||||
done
|
||||
#+end_src
|
||||
|
||||
** Slack
|
||||
What a nonsense of a program.
|
||||
|
||||
|
|
@ -656,42 +696,3 @@ System
|
|||
'(
|
||||
<<packages("system")>>))
|
||||
#+end_src
|
||||
|
||||
Finally, I also want to have an ability to use global npm. Some settings for that are located in [[file:Console::*npm][Console.org]]. Here we want to unset =NPM_CONFIG_USERCONFIG= if there is npm available in the environment.
|
||||
|
||||
So here is a script to set up conda hooks:
|
||||
#+begin_src bash :tangle ~/bin/scripts/setup-conda-npm
|
||||
# Get writable conda envs with npm & without
|
||||
readarray -t CONDA_ENVS_ALL <<< $(conda env list --json | jq '.envs[]')
|
||||
CONDA_ENVS_NPM=()
|
||||
CONDA_ENVS_NO_NPM=()
|
||||
for env in "${CONDA_ENVS_ALL[@]}"; do
|
||||
env="${env:1:${#env}-2}"
|
||||
if [ -w "$env" ]; then
|
||||
if [ -f "$env/bin/npm" ]; then
|
||||
CONDA_ENVS_NPM+=($env)
|
||||
else
|
||||
CONDA_ENVS_NO_NPM+=($env)
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
for env in "${CONDA_ENVS_NPM[@]}"; do
|
||||
echo "Found npm in $env"
|
||||
mkdir -p "$env/etc/conda/activate.d"
|
||||
mkdir -p "$env/etc/conda/deactivate.d"
|
||||
|
||||
echo "unset NPM_CONFIG_USERCONFIG" > "$env/etc/conda/activate.d/conda.sh"
|
||||
echo "set -e NPM_CONFIG_USERCONFIG" > "$env/etc/conda/activate.d/conda.fish"
|
||||
echo "export NPM_CONFIG_USERCONFIG=$HOME/._npmrc" > "$env/etc/conda/deactivate.d/conda.sh"
|
||||
echo "export NPM_CONFIG_USERCONFIG=$HOME/._npmrc" > "$env/etc/conda/deactivate.d/conda.fish"
|
||||
done
|
||||
|
||||
for env in "${CONDA_ENVS_NO_NPM}"; do
|
||||
echo "Did not found npm in $env"
|
||||
rm -rf "$env/etc/conda/activate.d/conda.sh" || true
|
||||
rm -rf "$env/etc/conda/activate.d/conda.fish" || true
|
||||
rm -rf "$env/etc/conda/deactivate.d/conda.sh" || true
|
||||
rm -rf "$env/etc/conda/deactivate.d/conda.fish" || true
|
||||
done
|
||||
#+end_src
|
||||
|
|
|
|||
61
bin/scripts/autocommit
Executable file
61
bin/scripts/autocommit
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env bash
|
||||
# [[file:../../Console.org::*=autocommmit=][=autocommmit=:1]]
|
||||
TIMEOUT_MIN=${TIMEOUT_MIN:-60}
|
||||
|
||||
export DISPLAY=:0
|
||||
cd "$1"
|
||||
|
||||
TIMESTAMP=$(date +%s)
|
||||
LAST_COMMIT_TIMESTAMP=$(git log -1 --format="%at" | xargs -I{} date -d @{} +%s)
|
||||
RECENTLY_CHANGED_NUM=$(find . -not -path '*/\.*' -mmin -$TIMEOUT_MIN | wc -l)
|
||||
CHANGED_NUM=$(git status --porcelain | wc -l)
|
||||
COMMITED="No"
|
||||
PUSHED="No"
|
||||
FETCHED="No"
|
||||
MERGED="No"
|
||||
|
||||
if [[ $(git ls-files -u | wc -l) -gt 0 ]]; then
|
||||
notify-send -u critical "Autocommit $(pwd)" "Merge conflict!"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ ($RECENTLY_CHANGED_NUM -eq 0 || $2 = "-F") && $CHANGED_NUM -gt 0 ]]; then
|
||||
read -r -d '' MESSAGE << EOM
|
||||
Autocommit $(date -Iminutes)
|
||||
|
||||
Hostname: $(hostname)
|
||||
EOM
|
||||
git add -A
|
||||
git commit -m "$MESSAGE"
|
||||
COMMITED="Yes"
|
||||
fi
|
||||
|
||||
NEED_TO_PUSH=$(git log origin/master..HEAD | wc -l)
|
||||
|
||||
git fetch && FETCHED="Yes" || FETCHED="No"
|
||||
if [[ $RECENTLY_CHANGED_NUM -gt 0 && $2 != '-F' ]]; then
|
||||
MERGED="Waiting"
|
||||
fi
|
||||
|
||||
if [[ ($RECENTLY_CHANGED_NUM -eq 0 || $2 = "-F") && $FETCHED = "Yes" ]]; then
|
||||
MERGE_OUT=$(git merge origin/master) && MERGED="Yes" || MERGED="No"
|
||||
fi
|
||||
|
||||
if [[ $NEED_TO_PUSH -gt 0 && ($MERGED = "Yes" || $MERGED = "Waiting") ]]; then
|
||||
git push origin && PUSHED="Yes" || PUSHED="No"
|
||||
fi
|
||||
|
||||
if [[ $PUSHED = "Yes" || $COMMITED = "Yes" || ($MERGED = "Yes" && $MERGE_OUT != "Already up to date.")]]; then
|
||||
read -r -d '' NOTIFICATION << EOM
|
||||
Commited: $COMMITED
|
||||
Fetched: $FETCHED
|
||||
Merged: $MERGED
|
||||
Pushed: $PUSHED
|
||||
EOM
|
||||
notify-send "Autocommit $(pwd)" "$NOTIFICATION"
|
||||
fi
|
||||
|
||||
if [[ $(git ls-files -u | wc -l) -gt 0 ]]; then
|
||||
notify-send -u critical "Autocommit $(pwd)" "Merge conflict!"
|
||||
fi
|
||||
# =autocommmit=:1 ends here
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#!/bin/sh
|
||||
COMMAND="buku -o %"
|
||||
# COMMAND="qutebrowser $(buku -f 10 -p %)"
|
||||
if [[ $1 == '-e' ]]; then
|
||||
COMMAND="buku -w %"
|
||||
fi
|
||||
buku -f 5 -p | awk -F'\t' -v OFS='\t' '{
|
||||
split($3, tags, ",")
|
||||
joined = sep = ""
|
||||
for (i = 1; i in tags; i++) {
|
||||
joined = joined sep "[" tags[i] "]"
|
||||
sep = " "
|
||||
}
|
||||
if ($1 != "waiting for input") {
|
||||
printf "%-5s %-40s %s\n", $1, $2, joined
|
||||
}
|
||||
}' | dmenu -l 20 | cut -d ' ' -f 1 | {
|
||||
read index;
|
||||
url=$(buku -f 10 p $index)
|
||||
echo $url
|
||||
# echo ${$()#"waiting for input"} | cut -d ' ' -f 1 | xargs -I % qutebrowser %
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Copyright [2019] andreasl
|
||||
# Copyright [2020] SqrtMinusOne
|
||||
|
||||
define_standard_settings() {
|
||||
selected_path="$HOME"
|
||||
history_file="${HOME}/.config/.edm_history"
|
||||
max_history_entries=3
|
||||
|
||||
choices=(
|
||||
'<open terminal here>'
|
||||
'.'
|
||||
'..'
|
||||
"$(ls "$selected_path")"
|
||||
"$(cat "$history_file")"
|
||||
)
|
||||
|
||||
open_command='xdg-open'
|
||||
open_terminal_command='setsid st'
|
||||
}
|
||||
define_standard_settings
|
||||
|
||||
write_selection_to_history_file() {
|
||||
sed -i "\:${selected_path}:d" "$history_file"
|
||||
printf '%s\n' "$selected_path" >> "$history_file"
|
||||
printf '%s\n' "$(tail -n "$max_history_entries" "$history_file")" > "$history_file"
|
||||
}
|
||||
|
||||
while : ; do
|
||||
dmenu_result="$(printf '%s\n' "${choices[@]}" | dmenu -p "$selected_path" -l 50)" || exit 1
|
||||
if [ "$dmenu_result" = '<open terminal here>' ]; then
|
||||
cd $selected_path && $open_terminal_command
|
||||
write_selection_to_history_file
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$dmenu_result" == "/"* ]]; then
|
||||
selected_path="${dmenu_result}"
|
||||
else
|
||||
selected_path="$(realpath "${selected_path}/${dmenu_result}")"
|
||||
fi
|
||||
if [ -f "$selected_path" ] || [ "$dmenu_result" = '.' ]; then
|
||||
$open_command "$selected_path"
|
||||
write_selection_to_history_file
|
||||
exit 0
|
||||
elif [ -d "$selected_path" ]; then
|
||||
choices=( '<open terminal here>' '.' '..' "$(ls "$selected_path")")
|
||||
else
|
||||
selected_path="$(dirname "$selected_path")"
|
||||
fi
|
||||
done
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
#!/bin/bash
|
||||
SELECTED=$(man -k . | dmenu -l 20 | awk '{print $1}')
|
||||
if [[ ! -z $SELECTED ]]; then
|
||||
man -Tpdf $SELECTED | zathura -
|
||||
fi
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#!/bin/sh
|
||||
#!/usr/bin/env sh
|
||||
# [[file:../../Console.org::*=nt= - exec command with a finished notification][=nt= - exec command with a finished notification:1]]
|
||||
command="$@"
|
||||
if [ ! -z "$command" ]; then
|
||||
start_time="$(date -u +%s)"
|
||||
|
|
@ -9,3 +10,4 @@ if [ ! -z "$command" ]; then
|
|||
else
|
||||
notify-send "Terminal" "Command execution complete"
|
||||
fi
|
||||
# =nt= - exec command with a finished notification:1 ends here
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/bash
|
||||
/home/pavel/Programs/miniconda3/bin/python /home/pavel/Code/mpd-watcher/mpd-watcher/watcher.py
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#!/bin/bash
|
||||
time=$(sunwait poll daylight rise ${LAT} $LON)
|
||||
|
||||
function on_sunset() {
|
||||
notify-send "Sunset" "$(date)"
|
||||
}
|
||||
|
||||
function on_sunrise() {
|
||||
notify-send "Sunrise" "$(date)"
|
||||
}
|
||||
|
||||
if [[ ${time} == 'DAY' ]]; then
|
||||
sunwait wait set && on_sunset
|
||||
else
|
||||
sunwait wait rise && on_sunrise
|
||||
fi
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/bash
|
||||
/home/pavel/Programs/miniconda3/bin/vmd $1 &
|
||||
3
bin/scripts/vpn-resolvconf-wrapper
Executable file
3
bin/scripts/vpn-resolvconf-wrapper
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
GUIX_PROFILE=.guix-extra-profiles/system/system ; . "$GUIX_PROFILE"/etc/profile
|
||||
update-resolv-conf.sh "$@"
|
||||
Loading…
Add table
Reference in a new issue