I have this problem every time I use a ( or any of " ' { [. I have plugin that automatically closes it by corresponding ) " ' } ] but I am stuck inside the parenthesis or inside double quotes
String s="I completed typing the string but my cursor is stuck right here |";
I want exit the enclosure by pressing something for all. In VScode I can press the same symbol if my cursor is right behind it and it gets past the enclosure or by pressing tab
I can exit the enclosure without reaching for right arrow
If your plugin is 'jiangmiao/auto-pairs' it has a variable called g:AutoPairsShortcutJump you can set as you want or use the default tha is Altn.
" Jump outside '"({
" -> default Alt-n
if !exists('g:AutoPairsShortcutJump')
let g:AutoPairsShortcutJump = '<A-l>'
endif
Note: If your cursor it close to the end atom you can just repeat that one to jump outside. For example:
Let's supose the character `|' represents your cursor
(|)
Just press closing parenthesis will jump outside
I have this code that creates 20 parallel sqlplus instances, doing some queries and exits:
#!/bin/sh
for i in $(seq 1 20);
do
echo "CREATE TABLE table_$i (id NUMBER NOT NULL);
select * from table_$i;
! sleep 30
select * from table_$i;
! sleep 30
DROP TABLE table_$i;" | sqlplus system/password &
done
wait
I need to adjust this code if possible so it would run for an hour with the following conditions:
Always stay on 20 connections, if one sqlplus instance is closed (Finished it's process) another one should open, i need to maintain a certain amount of connections for X amount of time.
Is there anything i can add to this code that will achieve what i need?
For looping during an hour, see https://stackoverflow.com/a/22735757/3220113
runsql() {
i="$1"
end=$((SECONDS+3600))
SECONDS=0
while (( SECONDS < end )); do
# Do what you want.
echo "CREATE TABLE table_$i (id NUMBER NOT NULL);
select * from table_$i;
! sleep 30
select * from table_$i;
! sleep 30
DROP TABLE table_$i;" | sqlplus system/password
sleep 1 # precaution when sqlplus fails, maybe wrong password
done
}
for i in $(seq 1 20); do
runsql $i &
done
wait
Explanation:
The main loop at the bottom starts the function runsql 20 times in the background.
The function runsql could use $1 everywhere, I copy it to i for code that looks like the original.
SECONDS is a counter that is changed every second by the shell, so we do not need to call date.
3600 is an hour.
Inside (( .. )) you can do math without $ in front of variables.
I need to know is it possible to interrupt a bash script using keys like ESC or ENTER? By sending SIGINT /CTRL + C I am able to do, but due to some reasons(Check note in the last line) I cannot use CTRL +C. So I need to have some custom way to cause an interrupt.
In other terms: In following script, cleanup function is called when CTRL + C is pressed. Now need to modify this behavior so that cleanup function should be called when some keys like ENTER OR ESC is pressed.
cleanup() {
#do cleanup and exit
echo "Cleaning up..."
exit;
}
echo "Please enter your input:"
read input
while true
do
echo "This is some other info MERGED with user input in loop + $input"
sleep 2;
echo "[Press CTRL C to exit...]"
trap 'cleanup' SIGINT
done
Query:
Is it possible to use custom keys for causing interrupts in bash?
If possible, how to achieve it?
Note:
Reason: This script is called from another C++ program which has its own trap handling. So the trap handling of this script is conflicting with the parent program and ultimately the terminal is getting hung. In my organization that program's code is frozen so I cannot change its behavior. I have to tweak this child script only.
Here is a dirty trick which is doing my work just fine. read and case statement options are the key. Here I am timing out read command so that while true continues unless esc or enter is pressed.
cleanup() {
#do cleanup and exit
echo "Cleaning up..."
exit;
}
exitFunction()
{
echo "Exit function has been called..."
exit 0;
}
mainFunction()
{
while true
do
echo "This is some other info MERGED with user input in loop"
IFS=''
read -s -N 1 -t 2 -p "Press ESC TO EXIT or ENTER for cleanup" input
case $input in
$'\x0a' ) cleanup; break;;
$'\e' ) exitFunction;break;;
* ) main;break;;
esac
done
}
mainFunction
Following works ^M for ENTER and ^[ for ESC but may
stty intr ^M
stty intr ^[
but after cannot use ENTER
to restore default
stty intr ^C
After comment, as the shell is interactive what about asking to continue instead using trap, also clean can be done in special EXIT trap.
How do I prompt for Yes/No/Cancel input in a Linux shell script?
or yet another solution using select
echo "Do you want to continue?"
PS3="Your choice: "
select number in Y N;
do
case $REPLY in
"N")
echo "Exiting."
exit
;;
"Y")
break
;;
esac
done
# continue
I have a problem in this line:
--description=\""$(<$varLeer/media/festplatte/txt/$varDesc)\""
I want it to get out the following:
--description="$(<$varLeer/media/festplatte/txt/$varDesc)"
But how do I get it that it does not "make use" of the letters "$(< and )" ?
I hope you understand what I mean. I read this tutorial (http://wiki.bash-hackers.org/syntax/quoting) but I don't understand how I can write down the "$(< and the )" without the shell using it "as Code".
To get maybe a bit clearer, I want to get the second code to be shwon but with the "$(< )" but marked as "real code".
What I tried is this - but it did not work:
--description=\"$(<"$varLeer/media/festplatte/txt/$varDesc\")"
//EDIT: Lets be much clearer at what I want to do.
There is a phyton script called "youtube-uploader" (https://code.google.com/p/youtube-upload/wiki/Readme). Now that I don't have to write "youtube-upload ....... INSERT VERY MUCH HERE ;)" every video I want that the uploaded parts get their title, description etc automatically. My idea was to just open my ytscript.bash with nano, edit the first top variables and then just do "sh ytscript.bash", insert my password and relax.
The part would be +1 every time the loop is used and with this there is automatically an own fitting title for every part. Here is my code so far:
#!/bin/bash
# Variablen
varSpielart="Lets Play: "
varSpielname="Diablo 3 "
varParttext="- PART "
varStartpart=1
varEndpart=2
varExtras=" [PS4][1080p]"
varKategorie=Games
varDesc="lpd3desc.txt"
varDateiname=lpd3
varDateiendung=.m4v
varKeywords="ps4, spieleule, piupload"
varPlaylist="UNDEFINIERT"
varAnzahlparts=`expr $varEndpart - $varStartpart`
varLeer=" "
echo "Gebe dein Passwort ein!"
read varPasswort
echo YT-UPLOAD: BEGINNE NEUEN UPLOAD
echo YT-UPLOAD: SPIEL $varSpielname
echo YT-UPLOAD: ANZAHL PARTS: $varAnzahlparts
varDurchgang=$varStartpart
while [ $varEndpart -gt $varDurchgang ]
do
cd youtube-upload
youtube-upload --email="email#email.de" --password=$varPasswort --private --category=$varKategorie --title=\""$varSpielart$varSpielname$varParttext$varDurchgang$varExtras\"" \
--description=$(<$varLeer/media/festplatte/txt/$varDesc) \
/media/festplatte/upload/$varDateiname"p"$varDurchgang""$varDateiendung &
varDurchgang=`expr $varDurchgang + 1`
echo Durchgang: $varDurchgang
echo Entpart: $varEndpart
echo Startpart: $varStartpart
echo Anzahlparts: $varAnzahlparts
done
The automatically title works like a charm (except giving me a " at the start and the end of the title on youtube.com without me wanting it! :( ). The description on youtube.com only gets a "" in it with the first answer under this question.
Try single quotes:
--description='"$(<$varLeer/media/festplatte/txt/$varDesc)"'
Try this
temp='$(<'$varLeer'/media/festplatte/txt/'$varDesc')'
--description=$temp
Sorry new to coding Applescript so any help is appreciated.
I'm trying to create a script that pastes text from clipboard into the middle of a telnet command. The output needs to be in the same window and look kind of like this:
I8,A,001
Q102,024
q448
rN
S4
D15
ZT
JF
O
R71,0
f100
N
B264,65,2,UA0,2,4,56,B,"100000000045"
A203,82,2,1,2,2,N,"xxxxx"
P1
The quoted 12 digit number on line 13 is what I need to insert.
This is what I've coded so far but it's not working:
tell application "Terminal"
do script "telnet xxx.xxx.xx.xx xxxx"
delay 1
do script "I8,A,001" in window 1
do script "Q102,024" in window 1
do script "q448" in window 1
do script "rN" in window 1
do script "S4" in window 1
do script "D15" in window 1
do script "ZT" in window 1
do script "JF" in window 1
do script "O" in window 1
do script "R71,0" in window 1
do script "f100" in window 1
do script "N" in window 1
do script "B264,65,2,UA0,2,4,56,B,\""
tell application "System Events"
tell application process "Terminal" in window 1
keystroke "v" using {command down}
end tell
keystroke "\""
keystroke return
do script "\"A203,82,2,1,2,2,N,\"xxxxx\""
do script "P1"
keystroke return
end tell
end tell
As soon as I try to use Command V to paste it exits the Terminal window and pastes whats on the clipboard on the script instead and it wont let me tell it to stay in Terminal window 1.
You do not need to use command-v to get the clipboard contents into your Terminal window. Applescript can get the clipboard and then you just add it to the other part of your string before "do script". Something like this works... of course you don't need the first line of the code because the clipboard should already have that value.
set the clipboard to "100000000045"
set t1 to "B264,65,2,UA0,2,4,56,B,\""
set t2 to the clipboard
set t to t1 & t2 & "\""
do script t in window 1
This is what I ended up using to get it to work in case anyone else needs it:
tell application "Terminal"
do script "telnet xxx.xxx.xx.xx xxxx"
delay 1
do script "I8,A,001" in window 1
do script "Q102,024" in window 1
do script "q448" in window 1
do script "rN" in window 1
do script "S4" in window 1
do script "D15" in window 1
do script "ZT" in window 1
do script "JF" in window 1
do script "O" in window 1
do script "R71,0" in window 1
do script "f100" in window 1
do script "N" in window 1
set t1 to "B264,65,2,UA0,2,4,56,B,\""
set t2 to the clipboard
set t to t1 & t2 & "\""
do script t in window 1
do script "A203,82,2,1,2,2,N,\"xxxxx\"" in window 1
do script "P1" in window 1
end tell
Thanks for the help regulus!