You are not logged in.

#1 2024-05-13 04:28:37

Crunchbang
Member
From: Script headers everywhere
Registered: 2024-04-25
Posts: 22

[SOLVED] Scripting Help: Code cleanup request.

I wrote a small bash wrapper to be used in XFCE4 and Thunar to handle xdg-open requests for a terminal to be handled by creating a new tab in guake and in thunars case automatically change to the selected directory. 

quake-open.sh

#!/bin/bash
IFS=$'\n'
DIR=$1
if [ -n "$DIR" ]; then
  CMD_STRING="cd '"'"'$DIR'"'"'"
  CMD="$(echo $CMD_STRING |sed 's/\"//g')" # Remove double quotes
  guake --show --new-tab XDG-OPEN -e $CMD
else
  guake --show --new-tab XDG-OPEN
fi

this just builds a string that is forwarded to quake to change to the selected directory in single quotes.  The resulting command is:

guake --show --new-tab XDG-OPEN -e "cd '/path/to/working dir/selected'"

this works perfectly well but I kinda hate how I did it, its ugly and possibly explotiable.  Can someone please take a look and  help me make it better?

Thanks! smile

Last edited by Crunchbang (2024-05-14 14:46:04)

Offline

#2 2024-05-13 07:00:14

seth
Member
Registered: 2012-09-03
Posts: 59,042

Re: [SOLVED] Scripting Help: Code cleanup request.

https://wiki.archlinux.org/title/Guake#Guake_scripting

… -n "$1"

?

Doesn't the -e syntax just switch the directory and then quit (instead of opening a shell) and what is "XDG-OPEN"?

Offline

#3 2024-05-13 07:08:11

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,116
Website

Re: [SOLVED] Scripting Help: Code cleanup request.

Because you misspelled it twice, and also in the script's name: quake (a game) != guake (a terminal emulator)


Inofficial first vice president of the Rust Evangelism Strike Force

Offline

#4 2024-05-13 13:14:55

Crunchbang
Member
From: Script headers everywhere
Registered: 2024-04-25
Posts: 22

Re: [SOLVED] Scripting Help: Code cleanup request.

seth wrote:

https://wiki.archlinux.org/title/Guake#Guake_scripting

… -n "$1"

?

Doesn't the -e syntax just switch the directory and then quit (instead of opening a shell) and what is "XDG-OPEN"?


WTF lol.   I’m not at my PC but I could swear -n is for new tab and the next arg is supposed to be title.    XDG-OPEN is just because you have to name the new tab or it fails lol.   Tab name is then changed to pwd as per guake preferences for me.   



-e definitely doesn’t just run then exit for me.   The posted example works without flaws but I think that the "cd '"'"'$DIR'"'"'"  is pretty nasty.    Possibly injectable garbage

Last edited by Crunchbang (2024-05-13 13:39:03)

Offline

#5 2024-05-13 15:23:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED] Scripting Help: Code cleanup request.

So the whole script could just be one command:

guake --show --new-tab "${1:-$HOME}"

Last edited by Trilby (2024-05-13 15:23:52)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2024-05-14 14:03:20

Crunchbang
Member
From: Script headers everywhere
Registered: 2024-04-25
Posts: 22

Re: [SOLVED] Scripting Help: Code cleanup request.

Trilby wrote:

So the whole script could just be one command:

guake --show --new-tab "${1:-$HOME}"

Yep!   Got home yesterday and confirmed that I’m an ID10T lol.     Changed to something very near this example. 

The way it’s written in the man pages appears like:  guake -n NEW_TAB and I assumed that to mean name without fully reading the meaning I guess. 


Anyways thanks all

Offline

Board footer

Powered by FluxBB