Skip to content

Instantly share code, notes, and snippets.

@mothsART

mothsART/.zshrc Secret

Created Mar 27, 2022
Embed
What would you like to do?
## launch thunar in multi tabs
thunar_apps() {
inc=0
for dir in "${@}"; do
if [ $inc = 0 ]; then
$SCRIPTS_PATH/thunar_multi_tabs.sh "$dir" "first"
else
$SCRIPTS_PATH/thunar_multi_tabs.sh "$dir" "others"
fi
inc+=1
done
}
#!/bin/sh
# Script to open new file manager tab instead of window (e.g., Thunar) in XFCE.
# Install dependencies: sudo apt install gridsite-clients xdotool # gridsite-clients contains urlencode
# Version 0.1
# Lock script to process multiple instances consecutively when "Open All" on Desktop.
if [ -d "${1}" ]; then
ME=`basename "$0"`;
LCK="/tmp/${ME}.LCK";
exec 8>$LCK;
flock -x 8; # lock $LCK
trap 'rm -f $LCK' exit # remove $LCK regardless of exit status
sleep .1 # hack to give time for each script to execute properly--weird!
fi
# Convert desktop file urls to thunar-friendly local paths.
# Accommodates special characters in directory names (!@#$, etc).
fileurl="${1}"
filepath="$(urlencode -d ${fileurl%/})/"
# Check for running instances of $app on current desktop/workspace.
app=thunar
wid=$(xdotool search --desktop $(xdotool get_desktop) --class $app)
lastwid=`echo $wid | grep -oE '[^ ]+$'` # Get PID of newest active thunar window.
# If $wid is null launch app with filepath.
if [ "${2}" = "first" ]; then
$app "$filepath"
# If app is already running, activate it and use shortcuts to paste filepath into path bar.
else
xdotool windowactivate --sync $lastwid key ctrl+t ctrl+l # Activate pathbar in thunar
xdotool type -delay 0 "$filepath" # "--delay 0" removes default 12ms between each keystroke
xdotool key Return
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment