Merge remote-tracking branch 'origin/pr/3355'

This commit is contained in:
Florian Bruhin 2017-12-05 13:22:36 +01:00
commit e97fbfdf56
15 changed files with 76 additions and 71 deletions

View File

@ -52,6 +52,10 @@ matrix:
language: node_js language: node_js
python: null python: null
node_js: "lts/*" node_js: "lts/*"
- os: linux
language: generic
env: TESTENV=shellcheck
services: docker
fast_finish: true fast_finish: true
cache: cache:

View File

@ -144,7 +144,7 @@ fi
pkill -f "${program_}" pkill -f "${program_}"
# start youtube download in stream mode (-o -) into temporary file # start youtube download in stream mode (-o -) into temporary file
youtube-dl -qo - "$1" > ${file_to_cast} & youtube-dl -qo - "$1" > "${file_to_cast}" &
ytdl_pid=$! ytdl_pid=$!
msg info "Casting $1" >> "$QUTE_FIFO" msg info "Casting $1" >> "$QUTE_FIFO"
@ -153,4 +153,4 @@ tail -F "${file_to_cast}" | ${program_} -
# cleanup remaining background process and file on disk # cleanup remaining background process and file on disk
kill ${ytdl_pid} kill ${ytdl_pid}
rm -rf ${tmpdir} rm -rf "${tmpdir}"

View File

@ -41,7 +41,7 @@
[ -z "$QUTE_URL" ] && QUTE_URL='http://google.com' [ -z "$QUTE_URL" ] && QUTE_URL='http://google.com'
url=$(echo "$QUTE_URL" | cat - "$QUTE_CONFIG_DIR/quickmarks" "$QUTE_DATA_DIR/history" | dmenu -l 15 -p qutebrowser) url=$(echo "$QUTE_URL" | cat - "$QUTE_CONFIG_DIR/quickmarks" "$QUTE_DATA_DIR/history" | dmenu -l 15 -p qutebrowser)
url=$(echo "$url" | sed -E 's/[^ ]+ +//g' | egrep "https?:" || echo "$url") url=$(echo "$url" | sed -E 's/[^ ]+ +//g' | grep -E "https?:" || echo "$url")
[ -z "${url// }" ] && exit [ -z "${url// }" ] && exit

View File

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
set -euo pipefail
# #
# Behavior: # Behavior:
# Userscript for qutebrowser which will take the raw JSON text of the current # Userscript for qutebrowser which will take the raw JSON text of the current
@ -19,29 +20,23 @@
# #
# Bryan Gilbert, 2017 # Bryan Gilbert, 2017
# do not run pygmentize on files larger than this amount of bytes
MAX_SIZE_PRETTIFY=10485760 # 10 MB
# default style to monokai if none is provided # default style to monokai if none is provided
STYLE=${1:-monokai} STYLE=${1:-monokai}
# format json using jq
FORMATTED_JSON="$(cat "$QUTE_TEXT" | jq '.')"
# if jq command failed or formatted json is empty, assume failure and terminate TEMP_FILE="$(mktemp)"
if [ $? -ne 0 ] || [ -z "$FORMATTED_JSON" ]; then jq . "$QUTE_TEXT" >"$TEMP_FILE"
echo "Invalid json, aborting..."
exit 1 # try GNU stat first and then OSX stat if the former fails
FILE_SIZE=$(
stat --printf="%s" "$TEMP_FILE" 2>/dev/null ||
stat -f%z "$TEMP_FILE" 2>/dev/null
)
if [ "$FILE_SIZE" -lt "$MAX_SIZE_PRETTIFY" ]; then
pygmentize -l json -f html -O full,style="$STYLE" <"$TEMP_FILE" >"${TEMP_FILE}_"
mv -f "${TEMP_FILE}_" "$TEMP_FILE"
fi fi
# calculate the filesize of the json document
FILE_SIZE=$(ls -s --block-size=1048576 "$QUTE_TEXT" | cut -d' ' -f1)
# use pygments to pretty-up the json (syntax highlight) if file is less than 10MB
if [ "$FILE_SIZE" -lt "10" ]; then
FORMATTED_JSON="$(echo "$FORMATTED_JSON" | pygmentize -l json -f html -O full,style=$STYLE)"
fi
# create a temp file and write the formatted json to that file
TEMP_FILE="$(mktemp --suffix '.html')"
echo "$FORMATTED_JSON" > $TEMP_FILE
# send the command to qutebrowser to open the new file containing the formatted json # send the command to qutebrowser to open the new file containing the formatted json
echo "open -t file://$TEMP_FILE" >> "$QUTE_FIFO" echo "open -t file://$TEMP_FILE" >> "$QUTE_FIFO"

View File

@ -76,6 +76,7 @@ crop-first-column() {
ls-files() { ls-files() {
# add the slash at the end of the download dir enforces to follow the # add the slash at the end of the download dir enforces to follow the
# symlink, if the DOWNLOAD_DIR itself is a symlink # symlink, if the DOWNLOAD_DIR itself is a symlink
# shellcheck disable=SC2010
ls -Q --quoting-style escape -h -o -1 -A -t "${DOWNLOAD_DIR}/" \ ls -Q --quoting-style escape -h -o -1 -A -t "${DOWNLOAD_DIR}/" \
| grep '^[-]' \ | grep '^[-]' \
| cut -d' ' -f3- \ | cut -d' ' -f3- \
@ -91,10 +92,10 @@ if [ "${#entries[@]}" -eq 0 ] ; then
die "Download directory »${DOWNLOAD_DIR}« empty" die "Download directory »${DOWNLOAD_DIR}« empty"
fi fi
line=$(printf "%s\n" "${entries[@]}" \ line=$(printf '%s\n' "${entries[@]}" \
| crop-first-column 55 \ | crop-first-column 55 \
| column -s $'\t' -t \ | column -s $'\t' -t \
| $ROFI_CMD "${rofi_default_args[@]}" $ROFI_ARGS) || true | $ROFI_CMD "${rofi_default_args[@]}" "$ROFI_ARGS") || true
if [ -z "$line" ]; then if [ -z "$line" ]; then
exit 0 exit 0
fi fi

View File

@ -64,7 +64,7 @@ die() {
javascript_escape() { javascript_escape() {
# print the first argument in an escaped way, such that it can safely # print the first argument in an escaped way, such that it can safely
# be used within javascripts double quotes # be used within javascripts double quotes
sed "s,[\\\'\"],\\\&,g" <<< "$1" sed "s,[\\\\'\"],\\\\&,g" <<< "$1"
} }
# ======================================================= # # ======================================================= #
@ -178,7 +178,7 @@ choose_entry_menu() {
if [ "$nr" -eq 1 ] && ! ((menu_if_one_entry)) ; then if [ "$nr" -eq 1 ] && ! ((menu_if_one_entry)) ; then
file="${files[0]}" file="${files[0]}"
else else
file=$( printf "%s\n" "${files[@]}" | "${MENU_COMMAND[@]}" ) file=$( printf '%s\n' "${files[@]}" | "${MENU_COMMAND[@]}" )
fi fi
} }
@ -236,7 +236,7 @@ pass_backend() {
if ((match_line)) ; then if ((match_line)) ; then
# add entries with matching URL-tag # add entries with matching URL-tag
while read -r -d "" passfile ; do while read -r -d "" passfile ; do
if $GPG "${GPG_OPTS}" -d "$passfile" \ if $GPG "${GPG_OPTS[@]}" -d "$passfile" \
| grep --max-count=1 -iE "${match_line_pattern}${url}" > /dev/null | grep --max-count=1 -iE "${match_line_pattern}${url}" > /dev/null
then then
passfile="${passfile#$PREFIX}" passfile="${passfile#$PREFIX}"
@ -269,7 +269,7 @@ pass_backend() {
break break
fi fi
fi fi
done < <($GPG "${GPG_OPTS}" -d "$path" ) done < <($GPG "${GPG_OPTS[@]}" -d "$path" )
} }
} }
# ======================================================= # =======================================================
@ -283,7 +283,7 @@ secret_backend() {
query_entries() { query_entries() {
local domain="$1" local domain="$1"
while read -r line ; do while read -r line ; do
if [[ "$line" =~ "attribute.username = " ]] ; then if [[ "$line" == "attribute.username ="* ]] ; then
files+=("$domain ${line#${BASH_REMATCH[0]}}") files+=("$domain ${line#${BASH_REMATCH[0]}}")
fi fi
done < <( secret-tool search --unlock --all domain "$domain" 2>&1 ) done < <( secret-tool search --unlock --all domain "$domain" 2>&1 )
@ -303,6 +303,7 @@ pass_backend
QUTE_CONFIG_DIR=${QUTE_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/qutebrowser/} QUTE_CONFIG_DIR=${QUTE_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/qutebrowser/}
PWFILL_CONFIG=${PWFILL_CONFIG:-${QUTE_CONFIG_DIR}/password_fill_rc} PWFILL_CONFIG=${PWFILL_CONFIG:-${QUTE_CONFIG_DIR}/password_fill_rc}
if [ -f "$PWFILL_CONFIG" ] ; then if [ -f "$PWFILL_CONFIG" ] ; then
# shellcheck source=/dev/null
source "$PWFILL_CONFIG" source "$PWFILL_CONFIG"
fi fi
init init
@ -311,7 +312,7 @@ simplify_url "$QUTE_URL"
query_entries "${simple_url}" query_entries "${simple_url}"
no_entries_found no_entries_found
# remove duplicates # remove duplicates
mapfile -t files < <(printf "%s\n" "${files[@]}" | sort | uniq ) mapfile -t files < <(printf '%s\n' "${files[@]}" | sort | uniq )
choose_entry choose_entry
if [ -z "$file" ] ; then if [ -z "$file" ] ; then
# choose_entry didn't want any of these entries # choose_entry didn't want any of these entries

View File

@ -35,17 +35,12 @@ get_selection() {
# Main # Main
# https://github.com/halfwit/dotfiles/blob/master/.config/dmenu/font # https://github.com/halfwit/dotfiles/blob/master/.config/dmenu/font
if [[ -s $confdir/dmenu/font ]]; then [[ -s $confdir/dmenu/font ]] && read -r font < "$confdir"/dmenu/font
read -r font < "$confdir"/dmenu/font
fi
if [[ $font ]]; then [[ $font ]] && opts+=(-fn "$font")
opts+=(-fn "$font")
fi
if [[ -s $optsfile ]]; then # shellcheck source=/dev/null
source "$optsfile" [[ -s $optsfile ]] && source "$optsfile"
fi
url=$(get_selection) url=$(get_selection)
url=${url/*http/http} url=${url/*http/http}

View File

@ -32,7 +32,7 @@ add_feed () {
if grep -Fq "$1" "feeds"; then if grep -Fq "$1" "feeds"; then
notice "$1 is saved already." notice "$1 is saved already."
else else
printf "%s\n" "$1" >> "feeds" printf '%s\n' "$1" >> "feeds"
fi fi
} }
@ -57,7 +57,7 @@ notice () {
# Update a database of a feed and open new URLs # Update a database of a feed and open new URLs
read_items () { read_items () {
cd read_urls cd read_urls || return 1
feed_file="$(echo "$1" | tr -d /)" feed_file="$(echo "$1" | tr -d /)"
feed_temp_file="$(mktemp "$feed_file.tmp.XXXXXXXXXX")" feed_temp_file="$(mktemp "$feed_file.tmp.XXXXXXXXXX")"
feed_new_items="$(mktemp "$feed_file.new.XXXXXXXXXX")" feed_new_items="$(mktemp "$feed_file.new.XXXXXXXXXX")"
@ -75,7 +75,7 @@ read_items () {
cat "$feed_new_items" >> "$feed_file" cat "$feed_new_items" >> "$feed_file"
sort -o "$feed_file" "$feed_file" sort -o "$feed_file" "$feed_file"
rm "$feed_temp_file" "$feed_new_items" rm "$feed_temp_file" "$feed_new_items"
fi | while read item; do fi | while read -r item; do
echo "open -t $item" > "$QUTE_FIFO" echo "open -t $item" > "$QUTE_FIFO"
done done
} }
@ -85,7 +85,7 @@ if [ ! -d "$config_dir/read_urls" ]; then
mkdir -p "$config_dir/read_urls" mkdir -p "$config_dir/read_urls"
fi fi
cd "$config_dir" cd "$config_dir" || exit 1
if [ $# != 0 ]; then if [ $# != 0 ]; then
for arg in "$@"; do for arg in "$@"; do
@ -115,7 +115,7 @@ if < /dev/null grep --help 2>&1 | grep -q -- -a; then
text_only="-a" text_only="-a"
fi fi
while read feed_url; do while read -r feed_url; do
read_items "$feed_url" & read_items "$feed_url" &
done < "$config_dir/feeds" done < "$config_dir/feeds"

View File

@ -25,12 +25,10 @@
[[ $QUTE_MODE == 'hints' ]] && title=$QUTE_SELECTED_TEXT || title=$QUTE_TITLE [[ $QUTE_MODE == 'hints' ]] && title=$QUTE_SELECTED_TEXT || title=$QUTE_TITLE
# try to add the task and grab the output # try to add the task and grab the output
msg="$(task add $title $@ 2>&1)" if msg="$(task add "$title" "$*" 2>&1)"; then
if [[ $? == 0 ]]; then
# annotate the new task with the url, send the output back to the browser # annotate the new task with the url, send the output back to the browser
task +LATEST annotate "$QUTE_URL" task +LATEST annotate "$QUTE_URL"
echo "message-info '$msg'" >> $QUTE_FIFO echo "message-info '$msg'" >> "$QUTE_FIFO"
else else
echo "message-error '$msg'" >> $QUTE_FIFO echo "message-error '$msg'" >> "$QUTE_FIFO"
fi fi

View File

@ -50,7 +50,7 @@ msg() {
MPV_COMMAND=${MPV_COMMAND:-mpv} MPV_COMMAND=${MPV_COMMAND:-mpv}
# Warning: spaces in single flags are not supported # Warning: spaces in single flags are not supported
MPV_FLAGS=${MPV_FLAGS:- --force-window --no-terminal --keep-open=yes --ytdl --ytdl-raw-options=yes-playlist=} MPV_FLAGS=${MPV_FLAGS:- --force-window --no-terminal --keep-open=yes --ytdl --ytdl-raw-options=yes-playlist=}
video_command=( "$MPV_COMMAND" $MPV_FLAGS ) IFS=" " read -r -a video_command <<< "$MPV_COMMAND $MPV_FLAGS"
js() { js() {
cat <<EOF cat <<EOF

View File

@ -6,7 +6,7 @@
case $TESTENV in case $TESTENV in
py3*-pyqt*) py3*-pyqt*)
exe=$(readlink -f .tox/$TESTENV/bin/python) exe=$(readlink -f ".tox/$TESTENV/bin/python")
full= full=
;; ;;
*) *)
@ -15,4 +15,4 @@ case $TESTENV in
;; ;;
esac esac
find . -name *.core -o -name core -exec gdb --batch --quiet -ex "thread apply all bt $full" "$exe" {} \; find . \( -name "*.core" -o -name core \) -exec gdb --batch --quiet -ex "thread apply all bt $full" "$exe" {} \;

View File

@ -21,23 +21,23 @@
# Stolen from https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh # Stolen from https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh
# and adjusted to use ((...)) # and adjusted to use ((...))
travis_retry() { travis_retry() {
local ANSI_RED="\033[31;1m" local ANSI_RED='\033[31;1m'
local ANSI_RESET="\033[0m" local ANSI_RESET='\033[0m'
local result=0 local result=0
local count=1 local count=1
while (( count < 3 )); do while (( count < 3 )); do
if (( result != 0 )); then if (( result != 0 )); then
echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2 echo -e "\\n${ANSI_RED}The command \"$*\" failed. Retrying, $count of 3.${ANSI_RESET}\\n" >&2
fi fi
"$@" "$@"
result=$? result=$?
(( result == 0 )) && break (( result == 0 )) && break
count=$(($count + 1)) count=$(( count + 1 ))
sleep 1 sleep 1
done done
if (( count > 3 )); then if (( count > 3 )); then
echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2 echo -e "\\n${ANSI_RED}The command \"$*\" failed 3 times.${ANSI_RESET}\\n" >&2
fi fi
return $result return $result
@ -96,6 +96,8 @@ case $TESTENV in
eslint) eslint)
npm_install eslint npm_install eslint
;; ;;
shellcheck)
;;
*) *)
pip_install pip pip_install pip
pip_install -r misc/requirements/requirements-tox.txt pip_install -r misc/requirements/requirements-tox.txt

View File

@ -14,6 +14,16 @@ elif [[ $TESTENV == eslint ]]; then
# travis env # travis env
cd qutebrowser/javascript || exit 1 cd qutebrowser/javascript || exit 1
eslint --color --report-unused-disable-directives . eslint --color --report-unused-disable-directives .
elif [[ $TESTENV == shellcheck ]]; then
SCRIPTS=$( mktemp )
find scripts/dev/ -name '*.sh' >"$SCRIPTS"
find misc/userscripts/ -type f -exec grep -lE '[/ ][bd]ash$|[/ ]sh$|[/ ]ksh$' {} + >>"$SCRIPTS"
mapfile -t scripts <"$SCRIPTS"
rm -f "$SCRIPTS"
docker run \
-v "$PWD:/outside" \
-w /outside \
koalaman/shellcheck:latest "${scripts[@]}"
else else
args=() args=()
[[ $TRAVIS_OS_NAME == osx ]] && args=('--qute-bdd-webengine' '--no-xvfb') [[ $TRAVIS_OS_NAME == osx ]] && args=('--qute-bdd-webengine' '--no-xvfb')

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
set -e
# This script downloads the given release from GitHub so we can mirror it on # This script downloads the given release from GitHub so we can mirror it on
# qutebrowser.org. # qutebrowser.org.
@ -16,16 +17,16 @@ mkdir windows
base="https://github.com/qutebrowser/qutebrowser/releases/download/v$1" base="https://github.com/qutebrowser/qutebrowser/releases/download/v$1"
wget "$base/qutebrowser-$1.tar.gz" || exit 1 wget "$base/qutebrowser-$1.tar.gz"
wget "$base/qutebrowser-$1.tar.gz.asc" || exit 1 wget "$base/qutebrowser-$1.tar.gz.asc"
wget "$base/qutebrowser-$1.dmg" || exit 1 wget "$base/qutebrowser-$1.dmg"
wget "$base/qutebrowser_${1}-1_all.deb" || exit 1 wget "$base/qutebrowser_${1}-1_all.deb"
cd windows cd windows
wget "$base/qutebrowser-${1}-amd64.msi" || exit 1 wget "$base/qutebrowser-${1}-amd64.msi"
wget "$base/qutebrowser-${1}-win32.msi" || exit 1 wget "$base/qutebrowser-${1}-win32.msi"
wget "$base/qutebrowser-${1}-windows-standalone-amd64.zip" || exit 1 wget "$base/qutebrowser-${1}-windows-standalone-amd64.zip"
wget "$base/qutebrowser-${1}-windows-standalone-win32.zip" || exit 1 wget "$base/qutebrowser-${1}-windows-standalone-win32.zip"
dest="/srv/http/qutebrowser/releases/v$1" dest="/srv/http/qutebrowser/releases/v$1"
cd "$oldpwd" cd "$oldpwd"

View File

@ -1,14 +1,12 @@
#!/bin/bash #!/usr/bin/env bash
if [[ $PWD == */scripts ]]; then [[ $PWD == */scripts ]] && cd ..
cd ..
fi
echo > crash.log echo > crash.log
while :; do while :; do
exit=0 exit=0
while (( $exit == 0)); do while (( exit == 0 )); do
duration=$(($RANDOM%10000)) duration=$(( RANDOM % 10000 ))
python3 -m qutebrowser --debug ":later $duration quit" http://www.heise.de/ python3 -m qutebrowser --debug ":later $duration quit" http://www.heise.de/
exit=$? exit=$?
done done