dotfiles

My personal dotfiles 💠️

commit 672bb08d1734751bbbcca17feffadcd583da57fb
parent 50d5d557b8cf716756434cf6cb6c3126ec9d53c0
Author: Pablo <pablo-escobar@riseup.net>
Date:   Fri, 13 Aug 2021 20:46:41 -0300

Converted most of my fish functions into shell scripts

Also updated the config script

Diffstat:
M.config/fish/config.fish | 1+
D.config/fish/functions/backup.fish | 37-------------------------------------
D.config/fish/functions/corona.fish | 50--------------------------------------------------
D.config/fish/functions/mkimg.fish | 5-----
D.config/fish/functions/mp3-dl.fish | 16----------------
D.config/fish/functions/nvim_install.fish | 20--------------------
M.local/bin/aliases.sh | 1-
A.local/bin/backup | 41+++++++++++++++++++++++++++++++++++++++++
M.local/bin/config | 9+++++----
A.local/bin/mkimg | 15+++++++++++++++
A.local/bin/mp3-dl | 38++++++++++++++++++++++++++++++++++++++
A.local/bin/nvim-install | 20++++++++++++++++++++
12 files changed, 120 insertions(+), 133 deletions(-)
diff --git a/.config/fish/config.fish b/.config/fish/config.fish
@@ -23,6 +23,7 @@ abbr vim     'nvim'
 abbr sc      'sc-im'
 abbr weather 'curl https://wttr.in/'
 abbr mutt    'neomutt'
+abbr matrix  'cmatrix'
 
 # Aliases
 source "$HOME/.local/bin/aliases.sh"
diff --git a/.config/fish/functions/backup.fish b/.config/fish/functions/backup.fish
@@ -1,37 +0,0 @@
-function backup -d "Backup my relevant data in my backup drive."
-  set date (date '+%Y-%m-%d')
-
-  # Backup the most important directories into an archive named after
-  # the machine this script is currently running on:
-  borg create                                                              \
-    --verbose                                                              \
-    --filter AME                                                           \
-    --list                                                                 \
-    --stats                                                                \
-    --show-rc                                                              \
-    --compression lz4                                                      \
-    --exclude-caches                                                       \
-    --exclude-from "$HOME/.local/share/excludefile"                        \
-    "/run/media/pablo/Seagate Backup Plus Drive/Backups/::$hostname-$date" \
-    "$HOME/.ssh"                                                           \
-    "$HOME/Archive"                                                        \
-    "$HOME/Documents"                                                      \
-    "$HOME/Passwords"                                                      \
-    "$HOME/Pictures"                                                       \
-    "$HOME/Music"                                                          \
-    "$HOME/Videos"                                                         \
-    "$HOME/.config"                                                        \
-    "$HOME/.local/share/excludefile"                                       \
-    "$HOME/.local/share/texmf"                                             \
-    "$HOME/.local/bin"                                                     \
-
-  gpg --export --armor pablo-escobar@riseup.net \
-    > "/run/media/pablo/Seagate Backup Plus Drive/pablo.asc" 
-
-  gpg --export-secret-keys --armor pablo-escobar@riseup.net \
-    > "/run/media/pablo/Seagate Backup Plus Drive/pablo-secret.asc" 
-
-  gpg --export-ownertrust \
-    > "/run/media/pablo/Seagate Backup Plus Drive/trustdb.txt" 
-end
-
diff --git a/.config/fish/functions/corona.fish b/.config/fish/functions/corona.fish
@@ -1,50 +0,0 @@
-#   __ _     _                                          
-#  / _(_)   | |                                         
-# | |_ _ ___| |__ ______ ___ ___  _ __ ___  _ __   __ _ 
-# |  _| / __| '_ \______/ __/ _ \| '__/ _ \| '_ \ / _` |
-# | | | \__ \ | | |    | (_| (_) | | | (_) | | | | (_| |
-# |_| |_|___/_| |_|     \___\___/|_|  \___/|_| |_|\__,_|
-#                                                      
-# Pablo Emilio Escobar Gavíria (C) 2020
-# You are free (as in freedom) to do whatever you please with this!
-
-# Filters the cached CSV and adds a header to it
-function __corona_select_csv -a country
-    echo '🚩️ Country, 😷️ Cases, 🤒️ New Cases, 💀️ Deaths, 😰️ New Deaths'
-
-    if test (string lower "$country") = all
-        cat "$HOME/.cache/corona.csv"
-    else
-        grep -Ei "^\"?($country|World)" "$HOME/.cache/corona.csv"
-    end
-end
-
-function corona -a country -d "Track corona-virus cases from fish-shell. 😷️"
-    if test -z "$country"
-        if test -f "$HOME/.cache/country.name"
-            set country (cat "$HOME/.cache/country.name" )
-        else
-            set country_code (curl -s https://ipinfo.io/country/)
-            set country (curl -s "https://restcountries.eu/rest/v2/alpha/$country_code/" | jq '.name' | sed 's/"//g')
-            echo "$country" > "$HOME/.cache/country.name" 
-        end
-    end
-
-    # Update the cache if it doesn't exists or if it hasn't been modified in
-    # over a day
-    set date (date +%Y-%m-%d)
-    not test -f "$HOME/.cache/corona.csv"
-    or test (stat -c %y "$HOME/.cache/corona.csv" | cut -d' ' -f1) != "$date"
-
-    if test "$status" -eq 0
-        curl -s https://corona-stats.online/\?format=json \
-            | jq -r '.data + [.worldStats] 
-                        | .[] 
-                        | [.country,.cases,.todayCases,.deaths,.todayDeaths] 
-                        | @csv' \
-            > "$HOME/.cache/corona.csv"
-    end
-
-    __corona_select_csv "$country" | csvlook -d ',' -e UTF-8
-end
-
diff --git a/.config/fish/functions/mkimg.fish b/.config/fish/functions/mkimg.fish
@@ -1,5 +0,0 @@
-function mkimg -a file -d "Creates a MS-DOS compatible disk image"
-  dd if=/dev/zero of="$file" count=1440 bs=1k
-  /sbin/mkfs.msdos "$file"
-end
-
diff --git a/.config/fish/functions/mp3-dl.fish b/.config/fish/functions/mp3-dl.fish
@@ -1,16 +0,0 @@
-function mp3-dl -a url
-  set input_dir (mktemp -d)
-
-  set title (youtube-dl --get-title "$url")
-  set format (youtube-dl -F "$url" | sed '/audio only/!d' | fzf --prompt='Which format do you prefer? ' | awk '{ print $1 }')
-  youtube-dl -f "$format" "$url" -o "$input_dir/input.%(ext)s"
-
-  if test "$format" = 'mp3'
-    mv $input_dirp/input.* "./$title.mp3"
-  else
-    ffmpeg -i $input_dir/input.* -c:a libmp3lame -ac 2 -q:a 2 "./$title.mp3"
-  end
-
-  rm -rf "$input_dir"
-end
-
diff --git a/.config/fish/functions/nvim_install.fish b/.config/fish/functions/nvim_install.fish
@@ -1,20 +0,0 @@
-function nvim_install -a url -d "install vim plugins from git repositories"
-
-    for repo in $argv
-        set sub_dir (echo "$url" | grep -o '[^/]*/[^/]*$' | grep -o '^[^/]*')
-        set pack (echo "$url" | grep -o '[^/]*$' | grep -o '^[^.]*')
-        set install_dir "$HOME/.local/share/nvim/site/pack/$sub_dir/start/$pack"
-
-        if test -d "$install_dir"
-            # Update the repository
-            set pwd (pwd)
-            cd "$install_dir"
-            git pull
-            cd "$pwd"
-        else
-            # Clone the repository
-            git clone "$url" "$install_dir"
-        end
-    end
-end
-
diff --git a/.local/bin/aliases.sh b/.local/bin/aliases.sh
@@ -24,5 +24,4 @@ alias ls='ls --color=auto'
 alias grep='grep --color=auto'
 alias fgrep='fgrep --color=auto'
 alias egrep='egrep --color=auto'
-alias matrix='cmatrix'
 
diff --git a/.local/bin/backup b/.local/bin/backup
@@ -0,0 +1,41 @@
+#!/bin/sh
+# Backup my relevant data in my backup drive.
+# 
+# Copyright (C) 2020 Pablo Emilio Escobar Gaviria.
+# Free use of this software is granted under the terms of the GPL-3.0 License.
+
+date="$(date '+%Y-%m-%d')"
+
+# Backup the most important directories into an archive named after
+# the machine this script is currently running on:
+borg create                                                              \
+  --verbose                                                              \
+  --filter AME                                                           \
+  --list                                                                 \
+  --stats                                                                \
+  --show-rc                                                              \
+  --compression lz4                                                      \
+  --exclude-caches                                                       \
+  --exclude-from "$HOME/.local/share/excludefile"                        \
+  "/run/media/pablo/Seagate Backup Plus Drive/Backups/::$hostname-$date" \
+  "$HOME/.ssh"                                                           \
+  "$HOME/Archive"                                                        \
+  "$HOME/Documents"                                                      \
+  "$HOME/Passwords"                                                      \
+  "$HOME/Pictures"                                                       \
+  "$HOME/Music"                                                          \
+  "$HOME/Videos"                                                         \
+  "$HOME/.config"                                                        \
+  "$HOME/.local/share/excludefile"                                       \
+  "$TEXMFHOME"                                                           \
+  "$HOME/.local/bin"                                                     \
+
+gpg --export --armor pablo-escobar@riseup.net \
+  > '/run/media/pablo/Seagate Backup Plus Drive/pablo.asc' 
+
+gpg --export-secret-keys --armor pablo-escobar@riseup.net \
+  > '/run/media/pablo/Seagate Backup Plus Drive/pablo-secret.asc' 
+
+gpg --export-ownertrust \
+  > '/run/media/pablo/Seagate Backup Plus Drive/trustdb.txt' 
+
diff --git a/.local/bin/config b/.local/bin/config
@@ -90,6 +90,7 @@ case "$1" in
     do
       echo "Adding '$item' to the list of dotfiles"
       realpath "$item" >> "$dotfiles_list"
+      call_git add "$item"
     done
     ;;
 
@@ -123,18 +124,18 @@ case "$1" in
 
     if grep modified "$config_git_status" > /dev/null;
     then
-      printf '\033[0;33mmodified files:\n'
+      printf '\033[0;33mmodified files:\033[0m\n'
       awk '/modified/ { print $2 }' "$config_git_status" \
         | xargs -r realpath \
-        | xargs -r -n 1 printf '    %s\033[0m\n'
+        | xargs -r -n 1 printf '\033[0;33m    %s\033[0m\n'
     fi
 
     if grep deleted "$config_git_status" > /dev/null;
     then
-      printf '\033[0;31mdeleted files:\n'
+      printf '\033[0;31mdeleted files:\033[0m\n'
       awk '/deleted/ { print $2 }' "$config_git_status" \
         | xargs -r realpath \
-        | xargs -r -n 1 printf '    %s\033[0m\n'
+        | xargs -r -n 1 printf '\033[0;31m    %s\033[0m\n'
     fi
 
     rm "$config_git_status"
diff --git a/.local/bin/mkimg b/.local/bin/mkimg
@@ -0,0 +1,15 @@
+#!/bin/sh
+# Creates a MS-DOS compatible disk image
+# 
+# Copyright (C) 2020 Pablo Emilio Escobar Gaviria.
+# Free use of this software is granted under the terms of the GPL-3.0 License.
+
+case "$1" in
+  -h|--help)
+    echo 'Usage: mkimg FILE'
+    ;;
+  *)
+    dd if=/dev/zero of="$1" count=1440 bs=1k
+    /sbin/mkfs.msdos "$1"
+    ;;
+esac
diff --git a/.local/bin/mp3-dl b/.local/bin/mp3-dl
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Downloads MP3 files from YouTube with youtube-dl
+# 
+# Copyright (C) 2020 Pablo Emilio Escobar Gaviria.
+# Free use of this software is granted under the terms of the GPL-3.0 License.
+
+getFormat() {
+  youtube-dl -F "$1" \
+    | sed '/audio only/!d' \
+    | fzf --prompt='Which format do you prefer? ' \
+    | cut -d ' ' -f1
+}
+
+case "$1" in
+  -h|--help)
+    echo 'Usage: mp3-dl URL'
+    ;;
+  *)
+    url="$1"
+    input_dir="$(mktemp -d)"
+    title="$(youtube-dl --get-title "$url")"
+
+    # Prompts the user to ask for the appropriate format to download
+    format="$(getFormat "$url")"
+
+    # Download the source from YouTube
+    youtube-dl -f "$format" "$url" -o "$input_dir/input.%(ext)s"
+
+    if [ "$format" = 'mp3' ]
+    then
+      mv $input_dirp/input.* "./$title.mp3"
+    else
+      ffmpeg -i $input_dir/input.* -c:a libmp3lame -ac 2 -q:a 2 "./$title.mp3"
+    fi
+
+    rm -rf "$input_dir"
+    ;;
+esac
diff --git a/.local/bin/nvim-install b/.local/bin/nvim-install
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+url="$1"
+
+for repo in "$@"
+do
+  sub_dir="$(echo "$url" | grep -o '[^/]*/[^/]*$' | grep -o '^[^/]*')"
+  pack="$(echo "$url" | grep -o '[^/]*$' | grep -o '^[^.]*')"
+  install_dir="$HOME/.local/share/nvim/site/pack/$sub_dir/start/$pack"
+
+  if [ -d "$install_dir" ]
+  then
+    # Update the repository
+    cd "$install_dir"
+    git pull
+  else
+    # Clone the repository
+    git clone "$url" "$install_dir"
+  fi
+done