How to set ranger as default file manager - shell

Related: Here, Here, Here, & Here.
I want to be able to use gui applications with ranger, e.g., I want to click a desktop folder icon & have it open in ranger.
Steps I take & errors that follow:
Set /home/ertecturing/.scripts/Ranger_Default_File_Manager.sh "%s" as default file manager in xfce settings
Ranger_Default_File_Manager.sh runs
xfce4-terminal -T "Ranger File Manager" -x ranger $#
This commands almost works, but it creates a directory error because directories given by $# always start with only file:/// not file://// like they need to in order to function.
I tried to add the missing 4th slash with this sed command someone shared with me:
OUT=$(sed -e 's/\/\/\//\/\/\/\//g' $1)
xfce4-terminal -T "Ranger File Manager" -x ranger $OUT
I have little idea whether that first line's syntax is correct.
The first line only produces blank output, but if I test a similar command echo $# | sed "s/\/\/\//\/\/\/\//g" >> ~/Desktop/file it always outputs the 4th slash I'm looking for.
Does anyone know a way to solve this issue? Help is highly appreciated.

Changing your OUT variable to the command that you say works may be a better approach.
OUT=$(echo "$#" | sed 's|$|/|g')

Additional Solution for Spaces:
OUT=$(echo "$#" | sed "s:///:////:g" | sed "s/%20/ /g")
xfce4-terminal -T "Ranger File Manager" -x ranger "$OUT"

Related

Adding printers by shell script; works in terminal but not as .command

I am trying to provide a clickable .command to set up printers in Macs for my workplace. I thought since it is something I do very frequently, I can write a shellscript for each printer and save it on a shared server. Then, when I need to add a printer for someone, I can just find the shell script on the server and execute it. My current command works in terminal, but once executed as a .command, it comes up with the errors.
This is my script:
#!/bin/sh
lpadmin -p ‘PRINTERNAME’ -D PRINTER\ NAME -L ‘OFFICE’ -v lpd://xx.xx.xx.xx -P /Library/Printers/PPDs/Contents/Resources/Xerox\ WorkCentre\ 7855.gz -o printer-is-shared=false -E​
I get this error after running the script:
lpadmin: Unknown option “?”.
I find this strange, because there is no "?" in the script.
I have a idea, why not try it like this ? there are huge differences between sh shells, so let me know if it rocks, I have more ideas.
#!/bin/sh
PPD="PRINTERNAME"
INFO="PRINTER\ NAME"
LOC="OFFICE"
URI="lpd://xx.xx.xx.xx"
OP ="printer-is-shared=false"
# This parameter P is new to me. Is it the paper-name ?
P="/Library/Printers/PPDs/Contents/Resources/Xerox\ WorkCentre\ 7855.gz"
lpadmin -p "$PPD" -D "$INFO" -L "$LOC" -v "$URI" -P "$P" -o "$OP" -E;

.bash_profile command arguments

I was looking for a redhat Tree command workaround and keep finding this specifically
alias lst='ls -R | grep ":$" | sed -e '"'"'s/:$//'"'"' -e '"'"'s/[^-][^\/]*\//--/g'"'"' -e '"'"'s/^/ /'"'"' -e '"'"'s/-/|/'"'"
I'm trying to add files to the output tree and I have no idea what any of this is saying, could someone tell me what this command is saying and how to add to it?

Why is this bash script not changing path?

I wrote a basic script which changes the directory to a specific path and shows the list of folders, but my script shows the list of files of the current folder where my script lies instead of which I specify in script.
Here is my script:
#!/bin/bash
v1="$(ls -l | awk '/^-/{ print $NF }' | rev | cut -d "_" -f2 | rev)"
v2=/home/PS212-28695/logs/
cd $v2 && echo $v1
Does any one knows what I am doing wrong?
Your current script makes no sense really. v1 variable is NOT a command to execute as you expect, but due to $() syntax it is in fact output of ls -t at the moment of assignment and that's why you have files from current directory there as this is your working directory at that particular moment. So you should rather be doing ordinary
ls -t /home/PS212-28695/logs/
EDIT
it runs but what if i need to store the ls -t output to variable
Then this is same syntax you already had, but with proper arguments:
v1=$(ls -t /home/PS212-28695/logs/)
echo ${v1}
If for any reason you want to cd then you have to do that prior setting v1 for the same reason I explained above.

Create log history excluding some command in bash MacOSX

impossible to find an answer to that:
i would like to create a log history of my command line automatically without having to do anything.
For that i found some clues, i modified my .bash_profile
but i need to exclude some command that i don't want in my log like "ls, cd, etc."
this doesn't work, and i can't d
so here's my code:
# log every command typed and when
command_out=( "more" "less" "cd" "open" "ls" "pwd" "nano" "man" "help") #array of command i don't want to save in my log
my_TEST=0 ##setup a var
FIRST_COMMAND=$(echo $BASH_COMMAND| cut -d' ' -f 1) ##get only the first command
## test if the first command is in the array
for elm in "${command_out[#]}"; do
if [[ $FIRST_COMMAND == $elm ]]; then
echo $elm # does not work
$my_TEST=1 ## if the command is in the array the var is setup to 1
fi
done
if [[ $my_TEST == 0 ]] && [ -n "${BASH_VERSION}" ]; then
trap "caller >/dev/null || \
printf '%s\\n' \"\$(date '+%Y-%m-%dT%H:%M:%S%z')\
\$(tty) \${BASH_COMMAND}\" 2>/dev/null >>~/.command_log" DEBUG
fi
if you any other ideas of how to do what i want i'm open
Thanks you
Bash automatically keeps a history of every command you type; you can use the history command to view it. If you want to exclude certain commands, rather than trying to exclude them from the log, I would skip them when viewing it, e.g. history | egrep -vw 'ls|cd|other|commands|here'.
You can set HISTTIMEFORMAT to get a timestamp with every entry, control how many commands are kept with HISTFILESIZE, and if you really want to keep some commands out instead of just not seeing them when you look, you can list them in HISTIGNORE. See https://www.gnu.org/software/bash/manual/html_node/Using-History-Interactively.html.
Your ~/.bash_history file should already contain your complete command history. You could use something like
cat ~/.bash_history | grep -v cd | egrep -v 'cd|ls|...'
to filter out the commands you're not interested in.
So for the list you specified:
cat ~/.bash_history | egrep -v 'more|less|cd|open|ls|pwd|nano|man|help'
I completed Mark Reed answer with what i precisely wanted. Here is my code:
# changes the .bash_history file mode to append
shopt -s histappend
#configures the history -a command to be run at each shell prompt. The -a immediately writes the current/new lines to the history file.
PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
#list of command i don't want in my history
HISTIGNORE='ls*:exit:pwd:clear:cd*:man*:more*:less*:head*:tail*:nano*:open*:help*'
#set no limit to the history file size
HISTSIZE= HISTFILESIZE=

How to filter the first 1 Sec of a Pcap file with Tshark in C#?

I have a small problem with filtering the first 1 second of a Pcap file and export it Via C# command. The command below execute just fine in CMD:
c:\Program Files\Wireshark\tshark.exe -r 10Secfile.pcap -T fields -E separator=, -E quote=d -e wlan_mgt.fixed.timestamp -e radiotap.mactime -e wlan_mgt.ssid -e radiotap.dbm_antsignal -e wlan.fc.type_subtype -R "frame.time_relative <=1.0" >> 1SecFile.txt
But when I try to do the exact same thing in C# like this:
strCmdText = "/C \"c:\\Program Files\\Wireshark\\tshark.exe\" -r 10SecFile.pcap -T fields -E separator=, -E quote=d -e wlan_mgt.fixed.timestamp -e radiotap.mactime -e wlan_mgt.ssid -e radiotap.dbm_antsignal -e wlan.fc.type_subtype -R \"frame.time_relative <=1.0\" >> 1SecFile.txt";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = new System.Diagnostics.ProcessStartInfo("CMD.exe", strCmdText);
process.Start();
process.WaitForExit();
I get this error: "the system cannot find the file specified command". And I am sure that all the paths to executables are found because the code works as soon as I remove the last filter:
-R \"frame.time_relative <=1.0\"
I even placed a breakpoint after "strCmdText=" and copied the value of it manually and pasted it into CMD and it works just fine.
I really appreciate if you help me to figure this out.
First I would like to thank #Guntram Blohm for the small but great tip which gave me the lead to go and search new topics.
I found this topic which explained my exact problem
So it's as Simple as adding
/S
Before "/C". I can not believe that everything works perfect now. The edited line is as follow:
cmd /S /C "Rest of your code/Command here"
Thanks a lot!

Resources