How to do this zsh script in bash?

Some things I really like about this:
a) the flexible case. it doesnt matter how your menu called $pmt looks like, it will always match by numbers (this is what the prompt function does)
b) the pid file for screencast and stopRecording
c) the dynamic entry for Screencast. It will change its name/action, if a screencast is already in place.
d) the really short delay prompt.
Can bash do these things too in an effecient way?
#!/bin/zsh
function prompt {
PROMPT_RESULT=$(echo ${(j:\n:)@} | dmenu -l 10 -p ${prompt_txt:-Teiler})
[[ "$PROMPT_RESULT" =~ "[0-9]+" ]] && echo $MATCH
function mainMenu {
prompt_txt='Teiler: '
isRecording && STATE_RECORDING=" 2. Stop recording screencast"
pmt=(" 0: Cancel"
" 1. Take screenshot"
${STATE_RECORDING:-" 2. Record screencast"}
" 3. Quick Screenshot (Fullscreen)"
" 4. Quick Screenshot (Area)"
" 5. Upload clipboard content (Delayed)"
" 6. Copy last image to clipboard"
" 7. Upload a file"
${CUSTOM_MENUS:+' 9. More menus!'})
case $(prompt $pmt) in
1) snapMenu ;;
2) isRecording && stopRecording || screencast ;;
3) screenshot ;;
4) screenshot -s ;;
5) notImplemented ;;
6) notImplemented ;;
7) notImplemented ;;
*) exit
esac
function snapMenu {
pmt=("<< Back to main menu"
" 1. Screenshot (Fullscreen)"
" 2. Screenshot (Area)"
" 3. Delayed Screenshot (Fullscreen)"
" 4. Delayed Screenshot (Area)")
case $(prompt $pmt) in
1) screenshot ;;
2) screenshot -s ;;
3) delayPrompt screenshot -d ;;
4) delayPrompt screenshot -s -d ;;
*) mainMenu
esac
function screencast {
(( $+commands[ffmpeg] && $+commands[xdotool] && $+commands[xwininfo] )) \
|| die "Missing dependencies!"
isRecording && {
notify "$time" 'Screencast already in progress'
die 'Already recording screeen'
[[ -f "${img_path}/lastvid.webm" ]] && rm "${img_path}/lastvid.webm"
ffmpeg $encopts "${img_path}/lastvid.webm" &
>$SCREENCAST_PIDFILE <<< $!
notify "$time" "Screencast started"
function stopRecording {
local pid
[[ -f $SCREENCAST_PIDFILE ]] && {
pid=$(<$SCREENCAST_PIDFILE)
isRecording && kill "$pid"
rm "$SCREENCAST_PIDFILE"
notify "$time" "Stopped recording"
archiveVid
return 0
function delayPrompt {
prompt_txt='Delay: '
t=$(prompt 2 5 10 20 30 "Cancel")
[[ "$t" =~ "[0-9]+" ]] || die "Canceled"
[[ $t* -gt 2 ]] && notify $time "Screenshot will be taken in $t seconds"
$@ $[$t+1]
function isRecording {
[[ -f $SCREENCAST_PIDFILE ]] && \
[[ "$(pgrep -l -F $SCREENCAST_PIDFILE)" =~ "[0-9]+ ffmpeg" ]]
function die { echo "$1"; exit ${2:-1} }
mainMenu
Last edited by Rasi (2014-02-02 19:04:03)

Looks a lt like a job for an array of descriptions, select for choosing what to do, and functions to do the thing requested. See the dining script below for inspiration.
#!/bin/bash
alacarte=(
'fish'
'eggs and ham'
'desert and leave'
eat() {
echo "nom nom $1"
select choise in "${alacarte[@]}"; do
case "$choise" in
desert)
eat "$choise"
break
eat "$choise"
esac
done
exit 0

Similar Messages

  • How to implement this Java Script?

    Hello,
    I have this script to remove the link from titles of web parts.  I am new to SharePoint 2013 development. I am not sure where to put it. Not sure what file to put it and how to implement it.  How can ensure this code gets run on pages through out
    my SharePoint 2013 site.
    jQuery(document).ready(function () {
           $('a').filter("[href='###']").each(function () {
            $(this).replaceWith($(this).html());
    Reference
    https://expectedexception.wordpress.com/2012/01/30/how-to-remove-the-list-view-web-part-title-bar-link/
    Paul

    Get the page Url from the website and go to Sharepoint Designer and browse the page and add the script within a scritp tag <script>jQuery(document).ready(function
           $('a').filter("[href='###']").each(function () {
            $(this).replaceWith($(this).html());
     });</script>
    how to open a site in SP Designer:
    https://support.office.com/en-ie/article/Open-a-SharePoint-site-94d33d70-3f07-4a8e-b5b5-1137a9c36e74
    another option is to find the global file that contain the scripts and add it as a method there. You can check these files by viewing source of the page.
    note also that the Jquery reference is needed for this code to execute.
    Fouad Roumieh

  • How to run unix shell script from java web applet

    hi all
    i have created one java applet. my apache web server is on unix server.
    i have created one shell script in same directory where my .class and .htm files reside...
    how to run this shell script from applet? it should search this .sh file on server and not on the client browser machine...
    thanks in advance

    I suppose you could make the shell script into a CGI, configure the server to execute CGIs, and then make the applet open the URL of that CGI.

  • How to Improve this PL/SQL script

    Hi All,
    I have a package/procedure that insert data into table but it takes time more than 2 days. Have any known how to modify this script to improve the performance and reduce loading time, The following code is procedure I used to insert data.....
    Procedure INSERT_DATA (p_month IN DATE, p_product_id IN NUMBER ) IS
    cursor c1 is select * from tab#1; --reference data
    cursor c2 is select * from tab#2;
    cursor c3 is select * from tab#3;
    cursor c4 is select * from tab#4;
    cursor c5 is select * from tab#5;
    v_rec claim_table%rowtype;
    Begin
    for c1rec in c1 loop
    exit when c1%notfound;
    call procedure in package....;
    open c2(c1rec.claim_no);
    fetch c2 into v_location_cd ,v_claim_type_cd ;
    close c2;
    v_rec.location_cd := v_location_cd;
    v_rec.claim_type_cd := v_claim_type_cd ;
    open c3(c1rec.claim_no);
    fetch c3 into v_col#3,v_col#4;
    close c3;
    v_rec.col#3 := v_col#3 ;
    v_rec.col#4 := v_col#4 ;
    open c4(c1rec.claim_no);
    fetch c4 into v_col#5,v_col#6;
    close c4;
    v_rec.col#5 := v_col#5 ;
    v_rec.col#6 := v_col#6 ;
    insert into claim_table values ( v_rec.location_cd, v_rec.claim_type_cd , v_rec.col#3 , .......) ;
    if (c1%rowcount/1000) = trunc(c1%rowcount /1000) then
         commit;
    end if;
    end loop;
    commit;
    Exception
    exception statement....
    commit;
    End;
    Thanks All,
    Mcka

    A copy and paste of a reply I posted just a hour or so ago to the exact same approach used by a poster in [url http://forums.oracle.com/forums/thread.jspa?threadID=636929]this thread.
    Yucky code IMO. You are using PL/SQL to drive a nested loop join. Why? SQL is by far more capable of joining tables and is not limited to a using a nested loop approach only.
    Also, as you are using PL/SQL to drive it, it means that each cursor fetch in each (nested) FOR loop is a slow context switch from PL/SQL to SQL, in order to ship the row's data from the SQL engine to the PL/SQL engine. Only then to have that very same data shipped back (via yet another context switch) to the SQL engine to be inserted into table4.
    This code violates one of the most rudimentary performance principles in Oracle - it is not maximizing SQL and it it not minimizing PL/SQL. It is doing the exact opposite.
    As for the ad-hoc commits inside the loop - this does not make much sense. This will generate more redo and more overheads. Also, when something goes pear shape in that process, some rows would have been processed and inserted and committed. Some not.
    In this case, how do you expect to restart the failed process at the very first row that failed to be committed and continue processing from there?

  • Under a GUI, I need to run a perl script, how to do this?

    Hi - I am writing a GUI for my clients and one of the things my program must do is run a perl script. I am able to run perl.exe but it seems like perl.exe is not running the script. I also tried to put the perl script in a batch file and then call the batch file from my java GUI program. I still get the same issue of just perl.exe running but thats not running the script. My last attempt was to write a small class to test if perl.exe can run the script under a command line. I got the perl.exe to run the perl script but how do I but implement that class in my GUI if my test class needs a command line? How can I run a command line in my GUI so the perl script can be run.
    The Runtime.getRuntime.exec(RunPerlScript) is not working like I want it.
    I also tried Runtime r = Runtime.getRuntime();
    Process p = r.exec(RunPerlScript);
    How can I run the MS-DOS prompt from my program if the Runtime Environment is running already. The Runtime Environment seems to not allow another prompt to be opened and from there I can run the perl script manually or automatically from my program.
    What does the "cmd /c start..." or "c:\\windows\\command.com..." do? I have seen that in the forum but it doesn't seem to be running the perl script. The perl.exe runs, but not the perl script. I need anyones help desperately. Damn microsoft, why did they remove completely the functionality of DOS. I have a feeling my program will run perfectly under a UNIX environment, because I needed to do was open another shell. Thats what I need in windows!
    Thank you for your help.
    Seigot

    hi
    I am working on this perl scripts do run on GUI's well the process command is fine try java 1.3 it works fine. if u need more help let me know
    all the best

  • Hello, iam using the latest version of firefox, whenever i login into my yahoo mail account i get a stop script error, the details of the error script is mentioned below , please suggest how to stop this : STOP ERROR

    Hello, iam using the latest version of firefox, whenever i login into my yahoo mail account i get a stop script error, the details of the error script is mentioned below , please suggest how to stop this
    the website is www.mail.yahoo.com. i was getting the same STOP script error every now and then in firefox 6 as well

    I have had a similar problem with my system. I just recently (within a week of this post) built a brand new desktop. I installed Windows 7 64-bit Home and had a clean install, no problems. Using IE downloaded an anti-virus program, and then, because it was the latest version, downloaded and installed Firefox 4.0. As I began to search the internet for other programs to install after about maybe 10-15 minutes my computer crashes. Blank screen (yet monitor was still receiving a signal from computer) and completely frozen (couldn't even change the caps and num lock on keyboard). I thought I perhaps forgot to reboot after an update so I did a manual reboot and it started up fine.
    When ever I got on the internet (still using firefox) it would crash after anywhere between 5-15 minutes. Since I've had good experience with FF in the past I thought it must be either the drivers or a hardware problem. So in-between crashes I updated all the drivers. Still had the same problem. Took the computer to a friend who knows more about computers than I do, made sure all the drivers were updated, same problem. We thought that it might be a hardware problem (bad video card, chipset, overheating issues, etc.), but after my friend played around with my computer for a day he found that when he didn't start FF at all it worked fine, even after watching a movie, or going through a playlist on Youtube.
    At the time of this posting I'm going to try to uninstall FF 4.0 and download and install FF 3.6.16 which is currently on my laptop and works like a dream. Hopefully that will do the trick, because I love using FF and would hate to have to switch to another browser. Hopefully Mozilla will work out the kinks with FF 4 so I can continue to use it.
    I apologize for the lengthy post. Any feedback would be appreciated, but is not necessary. I will try and post back after I try FF 3.16.6.

  • How to get this script to work with different browser

    Do you guys know how to get this script to work with mozilla firefox? 
    do shell script "open -a safari 'https://login.binck.nl/klanten/Login.aspx?ReturnUrl=%2fklanten%2fdefault.aspx'"
    tell application "Safari"
      activate
              tell document 1
                        repeat until ((do JavaScript "location.host") is "login.binck.nl")
                                  delay 1
                        end repeat
      do JavaScript"document.getElementById('ctl00_Content_Gebruikersnaam').value='sim';document.ge tElementById('ctl00_Content_Wachtwoord').value='password';window.open(document. g etElementById('ctl00_Content_LoginButton').href, '_self', 'true');"
              end tell
    end tell
    Thank you so much in advance:)

    That isn't possible. Firefox's AppleScript dictionary doesn't contain anything which can be used to manage JavaScripts.
    (63741)

  • How would I rewrite this shell script in PowerShell?

    This shell script lists the size of a directory and its subdirectories alphabetically then lists the name of the subdirectory with the highest disk usage along with its size. I'm completely new to PowerShell and would like to know how I would rewrite this
    script in PowerShell. Thanks in advance.
    #!/bin/sh
    myvar="$PWD"
    declare -i x=1
    while true; do
    $clear
    echo "Enter directory path or 1 for current directory ";
    read INPUT ;
    case "$INPUT" in
    1)INPUT="$myvar"
    esac
    echo "Disk space use (in KB) for each subdirectory ";
    if [ -d "$INPUT" ]
    then
    echo "Directory exists ";
    else
    echo "Directory does not exist ";
    fi
    for d in "$INPUT"/*; do
    if [ -d "$d" ]
    then
    du -h "$d"
    x=x+1;
    fi
    done
    echo "The subdirectory with the maximum disk space use:";
    du -m "$INPUT"| sort -nr | head -n 2
    done

    PowerShell uses looping constructs like any other scripting language. You'll need to at least make an attempt at translating this yourself because this forum isn't a free code-writing service. If you get stuck, you can ask for help.
    -- Bill Stewart [Bill_Stewart]

  • How can I get rid of this? script:chrome://messenger/content/mailWindows.js:173

    Hello,
    I have combed the internet for an answer but cannot find anything conclusive.
    Each time I open Thunderbird from scratch I get this message:
    script:chrome://messenger/content/mailWindows.js:173
    This has been going on for several days now.
    Once you answer the pop up question, one way or the other, the program carries on downloading messages.
    Any advice would be very welcome.
    I am on windows 8 home edition.
    Cheers
    Peter

    The error has nothing to do with the browser called chrome. It has to do with javascript in Thunderbird acting on the thunderbird chrome (that is the user interface your see.)
    If you have McAfee the first port of call is their chat support and ask them to check your settings. There are just to many permutations of "what works" as they have now released about 4 versions that mess up Thunderbird and all have a different fix.

  • How to execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • Downloading ML over 80 min's......how long will this go on???  MBP early 2011 running 10.7.3

    downloading ML over 80 min's......how long will this go on???  MBP early 2011 running 10.7.3

    I have a late 2009 MBP and I have noticed that just surfing the internet has caused the machine to run 20-30 degrees hotter. It used to hover around 40C (according to iStat...obviously it would climb under a load) when I was bumming around the net (no videos) and now it is anywhere between 60-70C doing the same stuff. I didn't really notice it till the other day when all I was doing was working on some bash scripts so at that point it was under very little load and it just seemed quite warm.

  • When I try to download the latest version of iTunes on my iPod Classic I get the message that "iTunes has an invalid signature" and that "Content was blocked because it was not signed by a valid security certificate.  Anyone know how to fix this?

    When I try to download the latest version of iTunes from apple.com, I get the message "Content was blocked because it was not signed by a valid security certificate."When I open iTunes and try to download the latest version there, I get the message "iTunes has an invalid signature.  The download has been removed."  I have also gotten an Internet Script Error stating that an error has occured in Line 0, Char O and that "Access is denied to images.apple.com/global/scripts/lib/iepngfix.htc."  This problem has never occurred with earlier versions of ITunes.  Anyone know how to fix this problem? 

    Are you downloading iTunes form an Apple website or somewhere else? If the answer is somewhere else, try downloading it from Apple. Click on iTunes in the black menu bar above and go from there.
    Let us know what happens.

  • How to do this in Procedure

    HI Friends,
    I am using Oracle 11 g.
    Please find the senarion and create table script with dummy data.
    In my_table we have data also like
    RA1340001,
    RA1340002
    In this case we need to change the data as
    R134B0001
    RB1340002
    For changing the letter B we need to go to a dcn_control table where we are maintain data like(SNO, DATE_T, CAMPGN_ID)
    (1,01-06-12,RA134)Suppose for this month the 2rd letter in CAMPGN_ID field is A then next month the letter is B alphabetically. Suppose the letter is Z then will update the data as A .
    So the logic shud be If data ='RA1340001' Then check the second letter and increment+1 alphabetically to B and place the B after R134 so the value is
    R134B0001
    If the data ='RA1340002' then check the second letter and increment+1 alphabetically to B so the value is RB1340002.
    ======================
    Please find the Table script.
    =================
    CREATE TABLE dcn_control
    SNO NUMBER NOT NULL,
    DATE_T date,
    CAMPGN_ID VARCHAR2(7 BYTE) NOT NULL)
    ==============================
    Create table my_table
    data varchar2(10)NOT Null
    ========================
    insert into my_table values(' RA1340001')
    insert into my_table values(' RA1340002')
    ================
    insert into dcn_control values(1,sysdate,'RA134')
    Please let me know how to do this.
    Thanks,
    Lony

    lony wrote:
    In this case we need to change the data as
    R134B0001
    RB1340002What is the logic behind it? Is it odd/even? If so:
    SELECT  t.data,
            u.campgn_id,
            CASE MOD(TO_NUMBER(SUBSTR(t.data,LENGTH(u.campgn_id) + 1)),2)
              WHEN 0 THEN SUBSTR(u.campgn_id,1,1) ||
                            CHR(
                                ASCII('A') +
                                  MOD(
                                      ASCII(SUBSTR(u.campgn_id,2,1)) - ASCII('A') + 1,
                                      26
                               ) ||
                            SUBSTR(t.data,3)
              ELSE SUBSTR(u.campgn_id,1,1) ||
                     SUBSTR(u.campgn_id,3) ||
                     CHR(
                         ASCII('A') +
                           MOD(
                               ASCII(SUBSTR(u.campgn_id,2,1)) - ASCII('A') + 1,
                               26
                        ) ||
                     SUBSTR(t.data,LENGTH(u.campgn_id) + 1)
            END res
      FROM  my_table t,
            dcn_control u
      WHERE t.data like u.campgn_id || '%'
    DATA       CAMPGN_ RES
    RA1340001  RA134   R134B0001
    RA1340002  RA134   RB1340002
    SQL> SY.

  • How to Use the JAVA SCRIPT code in .htm page of the component

    Hi .
    In my requirement i have to use Java Script Function in .htm code ..how to use the java script code and functions in .htm???
    thank you
    B.Mani

    Check this document  [Arun's Blog|http://wiki.sdn.sap.com/wiki/display/CRM/CRMWebClientUI-TalkingwithJava+Script]
    Regards
    Kavindra

  • How to import this chart in numbers?

    Hey guys,
    I have this numbers spreadsheet in which i would like to have this chart that is in the link underneath,
    now i know how to datascrape certain things but this chart uses javascript a language i do not fully understand.
    Does anyone know how to import this graph?
    The link is below
    http://www.bloomberg.com/quote/BDIY:IND
    If this question is too unrelated to numbers i will post this elsewhere if thats the case.
    Thank you very much in advance:)

    If you know the syntax used to download the values, it would be quite easy to write a script grabbing them and inserting them in a Numbers document.
    If you search for "insert quotes" in the existing threads you will find links pointing my existing scripts.
    If the script is edited to be usable as an idle one running in the background, you may get datas updated at the wanted frequency. A basis of one download every 10 minutes is a good starting point.
    Yvan KOENIG (VALLAURIS, France) dimanche 26 février 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.3
    My Box account  is : http://www.box.com/s/00qnssoyeq2xvc22ra4k

Maybe you are looking for

  • How can I get a file to copy all of the files in a directory except itself and the source of the copy function will be the directory the final program is in?

    How can I get a file to copy all of the files in a directory except itself and the source of the copy function will be the directory the final program is in? This application must be in Lab View 8.

  • Missing files in Photoshop 3

    Today I opened my catalog in Photoshop 3 for the who knows how many times and all looked fine. When I click onto any of the photos they appear grainy and have a broken orange box at the mid-bottom of all of them. A box then comes up 'searching for mi

  • F110 Isuse

    Hi Guru's i  want to  use Vendor payment transaction F110 with this additional functionality  saying that able to edit vendor payment proposals in USD currency. and laso how to active house bank which is not in not active? value points will be assign

  • Please suggest measures for tempdb.

    Q1) I am using express advance version of sqlserver 2008 r2, is there any limitation of temp db , why i am asking is because rowversion uses it heavely. What i have seen is, transactional data read by this sanpshot isolation level transaction will be

  • Standby VPN in the ASA 5505

    Hello, I'm triying find out if there is a way to put a second vpn site-to-site as standby and if the primary come down  this standby come to up. for exemplo, I have a ASA 5505 in my branch office I wish add two VPN site-to-site to my head office. one