Added newsboat

Update init.vim
This commit is contained in:
Uttarayan Mondal
2021-05-05 12:45:03 +05:30
parent 946c5d5d42
commit 2e750ef16d
6 changed files with 398 additions and 146 deletions

59
local/bin/news Executable file
View File

@@ -0,0 +1,59 @@
#!/usr/bin/env bash
PID=$$
export ID=$PID
DIR=/tmp/ueberzug_$PID
export UFIFO=$DIR/ufifo
# MAX_COLUMNS=60
IMAGE=$1
function cleanup {
# remove_image
stop_ueberzug
if [ -d "$DIR" ];then
rm -r $DIR
fi
exit
}
if [ ! -d "$DIR" ];then
mkdir $DIR
fi
source $(ueberzug library)
function start_ueberzug {
mkfifo $UFIFO
ImageLayer --silent <"$UFIFO" &
exec 3>"$UFIFO"
}
function stop_ueberzug {
exec 3>&-
rm $UFIFO &> /dev/null
}
# function set_image {
# x_size=$(tput cols)
# y_size=$(tput lines)
# MAX_COLUMNS=$(($x_size/5))
# x=$(($x_size-$MAX_COLUMNS-5))
# y=$(($y_size-5))
# echo $x $y
# ImageLayer::add [identifier]="$ID" [x]="${x}" [y]="${y}" \
# [max_width]="${MAX_COLUMNS}" \
# [path]="$@" \
# >"$UFIFO"
# }
# function remove_image {
# ImageLayer::remove [identifier]="$ID" \
# >"$UFIFO"
# }
trap cleanup EXIT
start_ueberzug
newsboat
cleanup

53
local/bin/newspager Executable file
View File

@@ -0,0 +1,53 @@
#!/usr/bin/env bash
if [ ! -p "$UFIFO" ];then
printf 'UFIFO not set\n'
exit
fi
# echo $ID
source $(ueberzug library)
function set_image {
x_size=$(tput cols)
y_size=$(tput lines)
MAX_COLUMNS=$(($x_size * 3 / 10 ))
# MAX_COLUMNS=100
x=$(($x_size-$MAX_COLUMNS-5))
y=$(($y_size/2))
ImageLayer::add [identifier]="$ID" [x]="${x}" [y]="${y}" \
[max_width]="${MAX_COLUMNS}" \
[path]="$@" \
>"$UFIFO"
}
function remove_image {
ImageLayer::remove [identifier]="$ID" \
>"$UFIFO"
}
IMG_URL=$(cat $@ | grep image | awk 'NR==2 {print $2}')
LINK=$(cat $@ | grep ^Link: | head -1 | cut -d: -f2-)
# echo $LINK
# non posix
# if [[ "$LINK" =~ "https://www.youtube.com/.*" ]];then
(
if [[ "$LINK" =~ "www.youtube.com" ]];then
# extract video id.
VIDEO_ID=$(echo $LINK | cut -d= -f2)
IMG_URL="https://img.youtube.com/vi/$VIDEO_ID/hqdefault.jpg"
# youtube-dl --write-thumbnail --skip-download $LINK --output /tmp/temp &> /dev/null
fi
if [ -n "$IMG_URL" ];then
curl -o /tmp/temp $IMG_URL &>/dev/null
fi
if [ -f "/tmp/temp" ];then
set_image /tmp/temp
fi
) &
nvim -R -c 'set ft=mail nomod noma nolist' -c 'nnoremap q :qa! <CR>' $@
remove_image
if [ -f /tmp/temp ];then
rm /tmp/temp
fi