From 3ffcadea920d5634e3c00c6da8d66f56554fd046 Mon Sep 17 00:00:00 2001 From: Ryan Greenup Date: Thu, 16 Jul 2020 08:38:42 +1000 Subject: [PATCH] Added First Tool PrintWebTitle --- bin/cadmus | 10 +-- bin/tools/PrintWebTitle.sh | 140 +++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+), 5 deletions(-) create mode 100755 bin/tools/PrintWebTitle.sh diff --git a/bin/cadmus b/bin/cadmus index 5c209ff..d429b22 100755 --- a/bin/cadmus +++ b/bin/cadmus @@ -180,9 +180,9 @@ function TagsHelp() { echo -e " • FilterNotesByTMSUTag.sh " echo -e " • tags-to-TMSU.sh " echo - echo -e " There very much so is an assumption that there is a .tmsu folder " - echo -e " somewhere above the NOTES_DIR " - echo -e " (in this case that is "${NOTES_DIR}")" + echo -e " There very much an assumption that there is a .tmsu folder " + echo -e " somewhere above the NOTES_DIR " + echo -e " (in this case that is "${NOTES_DIR}")" } @@ -194,7 +194,7 @@ CadmusTools () { while test $# -gt 0 do case "$1" in - filter) shift; "${script_dir}/tags/FilterNotesByTMSUTag.sh" "${NOTES_DIR}" "${@:-}" + webtitle) shift; "${script_dir}/tools/PrintWebTitle.sh" ;; create) shift; "${script_dir}/tags/tags-to-TMSU.sh" "${NOTES_DIR}" ${@:-} && exit 0 ./ @@ -218,7 +218,7 @@ function ToolsHelp() { echo echo -e " \e[1;91m \e[1m Command \e[0m\e[0m \e[1;34m┊┊┊ \e[0m Description " echo -e " ...........................\e[1;34m┊┊┊\e[0m........................................... " - echo -e " \e[1;93m WORKING url \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Transforms the Clipboard 📋 to a Link" + echo -e " \e[1;93m WORKING webtitle \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Transforms the Clipboard 📋 to a Link" echo -e " \e[1;93m TODO Print Backlinks \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Find Notes based on FileName" echo -e " \e[1;93m TODO Repair Link \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Find Notes based on FileName" echo -e " \e[1;32m TODO Import WebPage \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Search through Notes using Recoll" diff --git a/bin/tools/PrintWebTitle.sh b/bin/tools/PrintWebTitle.sh new file mode 100755 index 0000000..55c2b4f --- /dev/null +++ b/bin/tools/PrintWebTitle.sh @@ -0,0 +1,140 @@ +#!/bin/bash +# Don't forget to adjust the permissions with: +#chmod +x ~/somecrazyfolder/script1 + +## Program + + +### Description +# will print the title of a webpage +# I took the code from: + # https://unix.stackexchange.com/a/103253 + + +### Choose what format to output in + # LaTeX, # MD or # Org + + command -v recode >/dev/null 2>&1 || { echo >&2 "I require recode but it's not installed. install with sudo apt recode (or pacman its in the repos), Aborting."; exit 1; } + + +if [ "$1" == "-h" ]; then +# Put's formated link in clipboard + echo " + Usage: `basename $0` + + This requires GNU recode and GNU wget, they're in the repos + + -m... Format Link for Markdown........[Title](Link) + -o... Format Link for Org.............[[Link][Title]] + -l... Format Link for LaTeX...........href{Link}{Title} + " + exit 0 +fi + + +if [[ "$1" == *-m* ]]; then + echo "Will Export as markdown Format" + type="md" +elif [[ "$1" == *-o* ]]; then + echo "Will Export as Org Format" + type="org" +elif [[ "$1" == *-l* ]]; then + echo "Will Export as LaTeX Format" + type="latex" +else + echo " + + Please Specify an export Format + + m... Format Link for Markdown........[Title](Link) + o... Format Link for Org.............[[Link][Title]] + l... Format Link for LaTeX...........href{Link}{Title} + " + # Take the next single keystroke + read -d'' -s -n1 + type=$REPLY + + # reassign type to the corresponding keystroke + + if [[ $type == m ]]; then + echo "" + echo "Will Export as markdown Format" + type="md" + elif [[ $type == o ]]; then + echo "" + echo "Will Export as Org Format" + type="org" + elif [[ $type == l ]]; then + echo "" + echo "Will Export as LaTeX Format" + type="latex" + else + echo " + Correct input not detected. + either specify an argument or press the corresponding key, + refer to the help with `basename $0` -h. + " + exit 0 + + fi + fi + +# echo "The chosen format is $type" # To debug var assignment + +### Take the link Variable +arglink=$(xclip -o -selection clipboard) + +#### Print the Link + +##### Assign Colour Variables + +# taken from https://stackoverflow.com/a/5947802/10593632 +BLUE='\033[0;34m' +ORANGE='\033[0;33m' +NC='\033[0m' # No Color + +#printf "I ${BLUE}love${NC} Stack Overflow\n" +printf " + +The Chosen Link is: + +${BLUE} $arglink + +${NC} It's description is\n" + +title=$(wget -qO- $arglink | +perl -l -0777 -ne 'print $1 if /\s*(.*?)\s*<\/title/si' | +recode html..) + +echo $title + +### Return the Appropriate Ouput + +if [[ $type == md ]]; then + outputlink="[$title]($arglink)" +elif [[ $type == org ]]; then + outputlink="[[$arglink][$title]]" +elif [[ $type == latex ]]; then + outputlink="\href{$arglink}{$title}" +else + echo "the variable \$type doesn't match what was expected + despite correct input, this is a bug in the program + " + exit 1 +fi + + + +### Copy the link to the clipboard +echo $outputlink | xclip -selection clipboard + + + printf "The following link has been put in the clipboard: + + ${ORANGE} $outputlink \n" + +## vim:fdm=expr:fdl=0 +## vim:fde=getline(v\:lnum)=~'^##'?'>'.(matchend(getline(v\:lnum),'##*')-2)\:'=' + +exit 0 +