In zenity forms, how can I set default values (initialize) entries? - zenity

I've got a zenity form working, but I can't find any information on initializing the entries. The Zenity help manual webpage doesn't address the issue.
For example, the example from that webpage is
#!/bin/sh
zenity --forms --title="Add Friend" \
--text="Enter information about your friend." \
--separator="," \
--add-entry="First Name" \
--add-entry="Family Name" \
--add-entry="Email" \
--add-calendar="Birthday" >> addr.csv
case $? in
0)
echo "Friend added.";;
1)
echo "No friend added."
;;
-1)
echo "An unexpected error has occurred."
;;
esac
How would I initialize First Name, Last Name, etc. before displaying the window?

Use yad. It's a fork of zenity that I ended up using to overcome this missing functionality in zenity. The key is to use the --form option and include the initial values on the command line after the defined options and parameters. This "extra data" is assumed to be initial values for the fields.
initial_name_data='Jane Doe'; initial_email_data='jane#doe.org'
yad --form --title='Contact Info' --text='Edit Data' --field=Name --field=Email "$initial_name_data" "$initial_email_data"

yad --form --title='Contact Info' --text='Edit Data' --field=Name:CB --field=Email 'Joe Cool!^Jane Doe!Write Another Name' "JoeCool#home.net"
Joe Cool|JoeCool#home.net|
You should start the default option with ^ and separate each one with ! (notice that I enclose all of them with ' ... '

Related

Parsing arguments in fish shell without argparse

I'm using fish shell and wrote my own little parser function because I found argparse confusing. Basically, if a flag is matched, it uses the information from the following argument. However, I'm assuming my method must introduce bugs as I haven't seen this method used online. Are there advantages to using argparse that I'm missing?
function check_args
for current_arg in (seq 1 (count $argv))
#grab next argument
set next_arg $argv[(math $current_arg + 1)]
switch $argv[$current_arg]
case -h --help
usage
break
case -t --theme
echo "theme: " $next_arg
set -g theme themes/$next_arg.css
case -f --format
echo "format: " $next_arg
set -g format $next_arg
case -o --output
echo "output: " $next_arg
set -g output $next_arg
end
end
end
check_args $argv #calls the function with the passed arguments
With argparse:
# the -- is required!
argparse h/help t/theme= f/format= o/output= -- $argv
or exit 1
# just to inspect the variables
set -S _flag_h _flag_help _flag_t _flag_theme _flag_f _flag_format _flag_o _flag_output
if set -q _flag_help
usage
exit
end
set theme themes/$_flag_theme.css
set format $_flag_format
set output $_flag_output

How to export some data from Firebird database with FBExport?

I'm trying to export some data from a Firebird database, with FBExport to a CSV file.
The problem is I have two different errors. I spent a few hours to try different combinations:
Unknown switch -
Switches must begin with -
The command I tried:
fbexport -Sc -Q -F h:\AABBCC\export.csv -B -D h:\AABBCC\XXYYZZ.FDB -U "MMNNOO" -P "PPQQRR" -X "select PATIENTS.IPP, PATIENTS.NOM, PATIENTS.NOM_MARITAL, PATIENTS.NOM_USUEL, PATIENTS.PRENOMS, dmc.NUM_DOSSIER_PAPIER, dmc.NUM_DOSSIER_PAPIER_2, dmc.NUM_DOSSIER_PAPIER_3 from PATIENTS join dmc on PATIENTS.ipp = dmc.CODE where dmc.NUM_DOSSIER_PAPIER is not null or dmc.NUM_DOSSIER_PAPIER_2 is not null or dmc.NUM_DOSSIER_PAPIER_3 is not null;"
I absolutely don't understand what FBExport needs.
How can I export the data?
For me, the following command line works:
fbexport -Sc -D employee -U sysdba -P masterkey -F C:\Temp\export.csv -Q "select * from employee"
The problem in your original command was that you had a bare -Q, which caused the following -F to be interpreted as the argument of -Q, which then lead to h:\AABBCC\export.csv to be interpreted as an option, which then produced an error because it doesn't start with a -.
In addition, your command also had the following problems:
-B defines an alternative separator character for the produced CSV. It expects a separator character or TAB or \t for a tab. So, in similar vein as the previous problem, this would cause -D to be interpreted as an argument of -B, which then leads to h:\AABBCC\XXYYZZ.FDB to be interpreted as an option (without -).
-X is a primary option (like -S), to execute the query specified by -Q, instead of exporting (saving, -S). It doesn't accept a query text as argument, so the query text is also interpreted as an option (without -). This occurrence of -X should have been -Q.

Always show full prompt regardless of window width?

I have tried a few of the prompts that are available through the fish config tool. All of them have had prompts that become progressively shorter with a smaller window width. I personally don't like this as I always want to see the folder and git branch that I am in.
Is there a simple setting (or a popular off the shelf prompt) that makes the prompt be full width regardless of window width.
You can run the command fish_config, it will open a new tab in your browser, then select the Prompt tab and you will see some pre-setup prompts. If any of those suits you then you need to configure a prompt by yourself. On terminal you can do:
Go to .config/fish (generally it is located in your home folder. Linux or macOS you can do: cd ~/.config/fish
Create a folder named functions (mkdir functions ; cd functions)
Create a file named fish_prompt.fish with the content bellow:
function fish_prompt --description 'Informative prompt'
#Save the return status of the previous command
set -l last_pipestatus $pipestatus
switch "$USER"
case root toor
printf '%s#%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
and set_color $fish_color_cwd_root
or set_color $fish_color_cwd) \
(prompt_pwd) (set_color normal)
case '*'
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) \
(set_color --bold $fish_color_status) $last_pipestatus)
printf '\f\r> %s%s#%s %s%s %s%s%s' (set_color brblue) \
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD \
(set_color normal)
end
end
Please, note that the code bellow is adapted from the Informative prompt
The Awesome Fish repository has some interesting prompts that you can install if you like.

How to use gnuplot xdata time with feedgnuplot?

I'm using feedgnuplot and gnuplot to show real-time data on my linux desktop.
My data is produced by command which outputs 12 space separated integer values on each line and up to four lines per second.
I like to add the time, so I put time in front of the line before feeding data to feedgnuplot.
If I specify the time as seconds, the data is properly plotted, but the x-axis is quite unreadable:
data-producer |
while read -a line
do
echo -n $(date +"%s")
for n in "${line[#]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--xlen 5 \
--with lines \
--set "xdata time" \
--set "timefmt '%s'"
So I tried to get human readable time on the horizontal scale:
data-producer |
while read -a line
do
echo -n $(date +"%H:%M:%S")
for n in "${line[#]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--xlen 5 \
--with lines \
--set "xdata time" \
--set "timefmt '%H:%M:%S'"
This line does not work because feedgnuplot complains about comparison operators not applied to numeric data:
Argument "09:45:58" isn't numeric in numeric lt (<) at /usr/bin/feedgnuplot line 694.
Argument "09:45:57" isn't numeric in numeric ge (>=) at /usr/bin/feedgnuplot line 797.
Looking into the feedgnuplot code (it is a perl script) I see that comparison is performed on x values to sort them and to assess whether the graph has to be plotted again or not.
Is it possible to have feedgnuplot handle times by using some command line switches? If not, is there any other option before resorting to patching the feedgnuplot source code? Thank you.
Gnuplot requires some special settings for datetime data (e.g. a using statement must be specified). Therefore, feedgnuplot provides an own option for time data, --timefmt <format>:
for i in `seq 0 100`; do echo $i; sleep 1; done |
while read -a line
do
echo -n $(date +"%Y-%m-%d %H:%M:%S")
for n in "${line[#]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--lines \
--timefmt "%Y-%m-%d %H:%M:%S" \
--set 'format x "%H:%M:%S"'
Note, that different versions of gnuplot use different reference points for time in seconds, so that versions 4.6 (reference 1st January 2000) and earlier give wrong results when using %s. So it is better to use a time format of the kind %H:%M:%S. In the code above I used a fully defined datetime to avoid possible problems with day-spanning plots.

Passing value from TK to a file and replacing a variable

I am trying to interface between tk and cshell-script.
I am able to collect data using tk:
label .firstColumn.s.variable.label -text "myFirstVariable" -background $color3
entry .firstColumn.s.variable.entry -textvariable program
But when I try to run the command it does not work
button .secondColumn.o.buttons.go -text "Run Now" \
-command "exec sed -i {s/ABC/$myFirstVariable/g} runme.sh \
>! runmeNow.sh ; ./runmeNow"
It changes ABC to blank in runmeNow.sh file.
Is there any better way to achieve it?
I want to replace a place-holder predefined in cshell-script (runme.sh). My place holder is ABC. Then I want to pipe it to a different file, then run this file. runme.sh has UNIX based run file.
Seems to me that tk is interpreting $myFirstVariable as a variable of its own, while you'd like it to be forwarded to shell. Escaping the dollar sign with a backslash may not be enough: exec is a Tcl command and doesn't use a shell, so we may have to call one to expand shell variable:
button .secondColumn.o.buttons.go -text "Run Now" \
-command "exec /bin/sh -i {sed "s/ABC/$myFirstVariable/g" runme.sh \
> runmeNow.sh ; ./runmeNow.sh}"