dotfiles

My dotfiles for Arch Linux
git clone git@git.janispagel.de:dotfiles.git
Log | Files | Refs | README

commit 5ab059904d247d895c70a3eebda16d696c10e6e2
parent 1364c47cd59e59ae89115a8bdb033186fdaa6eae
Author: Janis Pagel <janis.pagel@ims.uni-stuttgart.de>
Date:   Sat, 12 Sep 2020 13:11:23 +0200

Add scripts

Diffstat:
Ascripts/.local/scripts/convert_bookmarks_html2text.sh | 6++++++
Ascripts/.local/scripts/convert_music_library.sh | 6++++++
Ascripts/.local/scripts/percsplit | 35+++++++++++++++++++++++++++++++++++
Ascripts/.local/scripts/rmspaces.sh | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/scripts/.local/scripts/convert_bookmarks_html2text.sh b/scripts/.local/scripts/convert_bookmarks_html2text.sh @@ -0,0 +1,6 @@ +#!/bin/env bash + +BOOKMARKS_HTML="$HOME/.bookmarks.html" +BOOKMARKS_TXT="$HOME/.bookmarks" + +paste -d' ' <(pup -f $BOOKMARKS_HTML "dt a attr{adddate}") <(pup -f $BOOKMARKS_HTML "dt a attr{href}") <(pup -f $BOOKMARKS_HTML "dt a text{}") | sort | cut -d' ' -f 2- > $BOOKMARKS_TXT diff --git a/scripts/.local/scripts/convert_music_library.sh b/scripts/.local/scripts/convert_music_library.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Script for converting all files in music library from flac to mp3 and write +# to folder for cell phone transfer +find ~/music -type f -iname "*.flac" -exec sh -c \ +'bn=${1##*/}; bn=${bn%.*}; ffmpeg -loglevel 16 -n -i "$1" "${0}${bn}.mp3"' ~/cell/music/ {} \; diff --git a/scripts/.local/scripts/percsplit b/scripts/.local/scripts/percsplit @@ -0,0 +1,35 @@ +usage () { + printf '%s\n' "${0##*/} [-ks] [-f prefix] [-n number] file arg1..." >&2 +} + +# Collect csplit options +while getopts "ksf:n:" opt; do + case "$opt" in + k|s) args+=(-"$opt") ;; # k: no remove on error, s: silent + f|n) args+=(-"$opt" "$OPTARG") ;; # f: filename prefix, n: digits in number + *) usage; exit 1 ;; + esac +done +shift $(( OPTIND - 1 )) + +fname=$1 +shift +ratios=("$@") + +len=$(wc -l < "$fname") + +# Sum of ratios and array of cumulative ratios +for ratio in "${ratios[@]}"; do + (( total += ratio )) + cumsums+=("$total") +done + +# Don't need the last element +unset cumsums[-1] + +# Array of numbers of first line in each split file +for sum in "${cumsums[@]}"; do + linenums+=( $(( sum * len / total + 1 )) ) +done + +csplit "${args[@]}" "$fname" "${linenums[@]}" diff --git a/scripts/.local/scripts/rmspaces.sh b/scripts/.local/scripts/rmspaces.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# Replace characters recursively +# Changes every occurence of $sourcechar with $targetchar +##################################### + +> /tmp/rmspaces_tmp.txt + +echo "0" > /tmp/rmspaces_tmp.txt + +if [ -z $1 ];then echo Give target directory; exit 0;fi + +change_counter=0 + +# define what character should be changed +# to what other character +sourcechar=' ' +targetchar='_' + + +find "$1" -depth -name '*' | while read file ; do + directory=$(dirname "$file") + oldfilename=$(basename "$file") + newfilename=$(echo "$oldfilename" | tr "$sourcechar" "$targetchar") + if [ "$oldfilename" != "$newfilename" ]; + + then + + mv -i "$directory/$oldfilename" "$directory/$newfilename" + echo ""$directory/$oldfilename" ---> "$directory/$newfilename"" + + change_counter=$(($change_counter+1)) + + echo "$change_counter" > /tmp/rmspaces_tmp.txt + + #echo "$directory" + #echo "$oldfilename" + #echo "$newfilename" + #echo + + fi + done + +change_counter=$(</tmp/rmspaces_tmp.txt) + +if [ $change_counter -eq 0 ]; + +then + + echo "No files have to be renamed." + +else + + if [ $change_counter -eq 1 ]; + + then + + echo ""$change_counter" file was renamed." + + else + + echo ""$change_counter" files were renamed." + + fi + +fi + +rm /tmp/rmspaces_tmp.txt + +echo "Done." + +exit 0