Added swap ncmpppppppp script, a little messing aroudn with booksearch

master
Steven Saus 4 years ago
parent 23689f5b1d
commit f1833f092c
  1. 74
      books_search.sh
  2. 79
      swap_ncmpcpp

@ -0,0 +1,74 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Info:
# author: Miroslav Vidovic
# file: books-search.sh
# created: 13.08.2017.-08:06:54
# revision: ---
# version: 1.0
# https://github.com/miroslavvidovic/rofi-scripts
# -----------------------------------------------------------------------------
# Requirements:
# rofi
# Description:
# Use rofi to search my books.
# Usage:
# books-search.sh
# -----------------------------------------------------------------------------
# Script:
# Books directory
BOOKS_DIR=~/Books
mkdir -p ~/Books
# Save find result to F_ARRAY
readarray -t F_ARRAY <<< "$(find "$BOOKS_DIR" -type f -name '*.pdf')"
# Associative array for storing books
# key => book name
# value => absolute path to the file
# BOOKS['filename']='path'
declare -A BOOKS
# Add elements to BOOKS array
get_books() {
# if [ ${#F_ARRAY[@]} != 0 ]; then
if [[ ! -z ${F_ARRAY[@]} ]]; then
for i in "${!F_ARRAY[@]}"
do
path=${F_ARRAY[$i]}
file=$(basename "${F_ARRAY[$i]}")
BOOKS+=(["$file"]="$path")
done
else
echo "$BOOKS_DIR is empty!"
echo "Please put some books in it."
echo "Only .pdf files are accepted."
exit
fi
}
# List for rofi
gen_list(){
for i in "${!BOOKS[@]}"
do
echo "$i"
done
}
main() {
get_books
book=$( (gen_list) | rofi -dmenu -i -matching fuzzy -no-custom -location 0 -p "Book > " )
if [ -n "$book" ]; then
xdg-open "${BOOKS[$book]}"
fi
}
main
exit 0

@ -0,0 +1,79 @@
#! /bin/bash
#this is to switch ncmpcpp
#Declarations
hoststring0="PASS@HOST #2 (or just HOST if no password set)"
hoststring1="PASS@HOST #2 (or just HOST if no password set)"
current=""
pid=""
function getInfo() {
#mpdinfo=$(mpc --host "$hoststring" )
playingstring=$(echo "$mpdinfo" | head -1 | awk -F '[' '{print $1}' | fold -sw 58 | head -1 )
percent=$(echo "$mpdinfo" | tail -2 | head -1 | awk '{print $4}')
printf "%s: %s" "$playingstring" "$percent"
}
function isplaying() {
mpdinfo=$(mpc --host "$hoststring" | sed -e 's/[/()&]//g')
progress=$(echo "$mpdinfo" | tail -2 | head -1 | awk '{print $1" "$3 $4}')
check=$(echo "$progress" | grep -c '\[')
}
function main() {
#note to self you could check for the entire name of the process too and
# whether or not it has the specified host
while true; do
hoststring=${hoststring1} #check remote
isplaying
echo "ah"
if [ $check != 0 ];then #remote is playing
if [ "$current" != "$hoststring" ];then # only do if we aren't currently on that host
current=${hoststring}
if [ ! -z $pid ];then
kill -9 "$pid" &> /dev/null
fi
eval ncmpcpp --host "$hoststring"
pid=$(echo $!)
current=${hoststring}
continue
fi
fi
hoststring=${hoststring0} #check local
if [[ -z "$NotFirst" ]];then
NotFirst="We've run once"
check=1
echo "FA"
current="First Time!"
echo "$check $hoststring"
fi
if [ $check != 0 ];then #local is playing
if [ "$current" != "$hoststring" ];then # only do if we aren't currently on that host
current=${hoststring}
if [ ! -z $pid ];then
kill -9 "$pid" &> /dev/null
fi
eval ncmpcpp --host "$hoststring"
pid=$(echo $!)
continue
fi
fi
echo "If you are seeing this, neither MPD instance is running. Ctrl-C to exit or start one to resume!"
mpc --host "$hoststring" idle &> /dev/null
done
}
current=${hoststring0} #starting it locally so the idle loop has a place to go
main
Loading…
Cancel
Save