How to disable VSCode additional terminal output beginning with "+++ __vsc"? - visual-studio-code

From some time onwards every time I use VSCode's integrated terminal I get a bunch of additional messages at the end like:
+++ __vsc_preexec_only scripts/calgary_brain_256_218_16_revi_2670_qpwls.sh
+++ '[' 0 = 0 ']'
+++ __vsc_in_command_execution=1
+++ __vsc_preexec
+++ __vsc_initialized=1
+++ [[ ! __vsc_prompt_cmd =~ ^__vsc_prompt* ]]
+++ __vsc_current_command=
+++ __vsc_command_output_start
+++ builtin printf '\033]633;C\007'
+++ builtin printf '\033]633;E;%s\007' ''
++ __vsc_prompt_cmd
++ __vsc_status=130
++ __vsc_precmd
++ __vsc_command_complete 130
++ '[' '' = '' ']'
++ builtin printf '\033]633;D\007'
++ __vsc_update_cwd
++ builtin printf '\033]633;P;Cwd=%s\007' /home/rexfung/code/SNOPY_EPI
++ __vsc_current_command=
++ __vsc_update_prompt
++ '[' 1 = 1 ']'
++ [[ \[\](mirtorch_110) \[\]\[\e]0;\u#\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ \[\]\[\] == '' ]]
++ [[ \[\](mirtorch_110) \[\]\[\e]0;\u#\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ \[\]\[\] != \\\[\]\6\3\3\;\A\\\\]\(\m\i\r\t\o\r\c\h\_\1\1\0\)\ \\\[\]\6\3\3\;\A\\\\]\\\[\\\e\]\0\;\\\u\#\\\h\:\ \\\w\\\a\\\]\$\{\d\e\b\i\a\n\_\c\h\r\o\o\t\:\+\(\$\d\e\b\i\a\n\_\c\h\r\o\o\t\)\}\\\[\\\0\3\3\[\0\1\;\3\2\m\\\]\\\u\#\\\h\\\[\\\0\3\3\[\0\0\m\\\]\:\\\[\\\0\3\3\[\0\1\;\3\4\m\\\]\\\w\\\[\\\0\3\3\[\0\0\m\\\]\\\$\ \\\[\]\6\3\3\;\B\\\\]\\\[\]\6\3\3\;\B\\\\] ]]
++ [[ \[\]> \[\] == '' ]]
++ [[ \[\]> \[\] != \\\[\]\6\3\3\;\F\\\\]\>\ \\\[\]\6\3\3\;\G\\\\] ]]
++ __vsc_in_command_execution=0
This also shows up even if I just interrupt with ^C
Any idea why this happens? How do I make this go away?
Thanks
I tried to relaunching VSCode but had no luck. These messages do not show up when I use a terminal outside of VSCode.

Related

Subset a string in POSIX shell

I have a variable set in the following format:
var1="word1 word2 word3"
Is it possible to subset/delete one of the space-delimited word portably? What I want to archive is something like this:
when --ignore option is supplied with the following argument
$ cmd --ignore word1 # case 1
$ cmd --ignore "word1 word2" # case2
I want the var1 changes to have only the following value
"word2 word3" # case1
"word3" #case2
If there is no way to achieve above described, is there a way to improve the efficiency of the following for loop? (The $var1 is in a for loop so my alternative thought to achieve similar was having following code)
# while loop to get argument from options
# argument of `--ignore` is assigned to `$sh_ignore`
for i in $var1
do
# check $i in $sh_ignore instead of other way around
# to avoid unmatch when $sh_ignore has more than 1 word
if ! echo "$sh_ignore" | grep "$i";
then
# normal actions
else
# skipped
fi
done
-------Update-------
After looking around and reading the comment by #chepner I now temporarily using following code (and am looking for improvement):
sh_ignore=''
while :; do
case
# some other option handling
--ignore)
if [ "$2" ]; then
sh_ignore=$2
shift
else
# defined `die` as print err msg + exit 1
die 'ERROR: "--ignore" requires a non-empty option argument.'
fi
;;
# handling if no arg is supplied to --ignore
# handling -- and unknown opt
esac
shift
done
if [ -n "$sh_ignore" ]; then
for d in $sh_ignore
do
var1="$(echo "$var1" | sed -e "s,$d,,")"
done
fi
# for loop with trimmed $var1 as downstream
for i in $var1
do
# normal actions
done
One method might be:
var1=$(echo "$var1" |
tr ' ' '\n' |
grep -Fxv -e "$(echo "$sh_ignore" | tr ' ' '\n')" |
tr '\n' ' ')
Note: this will leave a trailing blank, which can be trimmed off via var1=${var1% }

posix sh: how to count number of occurrences in a string without using external tools?

In bash, it can be done like this:
#!/bin/bash
query='bengal'
string_to_search='bengal,toyger,bengal,persian,bengal'
delimiter='|'
replace_queries="${string_to_search//"$query"/"$delimiter"}"
delimiter_count="${replace_queries//[^"$delimiter"]}"
delimiter_count="${#delimiter_count}"
echo "Found $delimiter_count occurences of \"$query\""
Output:
Found 3 occurences of "bengal"
The caveat of course is that the delimiter cannot occur in 'query' or 'string_to_search'.
In POSIX sh, string replacement is not supported. Is there a way this can be done in POSIX sh using only shell builtins?
#!/bin/sh
query='bengal'
string_to_search='bengal,toyger,bengal,persian,bengal'
ct() (
n=0
IFS=,
q=$1
set $2
for t in "$#"; do
if [ "$t" = "$q" ]; then
n=$((n + 1))
fi
done
echo $n
)
n=$(ct "$query" "$string_to_search")
printf "found %d %s\n" $n $query
Though I'm not sure what the point is. If you've got a posix shell,
you also almost certainly have printf, sed, grep, and wc.
printf '%s\n' "$string_to_search" | sed -e 's/,/\n/g' | grep -Fx "$query" | wc -l
Think I got it...
#!/bin/sh
query='bengal'
string_to_search='bengal,toyger,bengal,persian,bengal'
i=0
process_string="$string_to_search"
while [ -n "$process_string" ]; do
case "$process_string" in
*"$query"*)
process_string="${process_string#*"$query"}"
i="$(( i + 1 ))"
;;
*)
break
;;
esac
done
echo "Found $i occurences of \"$query\""

how to use * in sh string comparison

How to correctly use * in sh? I tried googling it but couldn't find anything. The following echo ture. why is that?
file="test test"
if [ "$file" != "te"* ]
then
echo true
else
echo false
fi
To avoid all the potential problems, when using POSIX shell, you should consider using the old expr regex or match expressions. Your choices are:
#!/bin/sh
file="test test"
if [ $(expr "$file" : "te.*") -gt 0 ]
then
echo true
else
echo false
fi
or
if [ $(expr substr "$file" 1 2) = "te" ]
then
echo true
else
echo false
fi
Not elegant, but they are the proper tools for the shell. A short explanation of each and the expr syntax for each is:
string : regularExp : returns the length of string if both sides match,
returns 0 otherwise
match string regularExp : same as the previous one
substr string start length : returns the substring of string starting from
start and consisting of length characters
I did a bit of googling and found a good bash scripting resource:
Advanced Bash-Scripting Guide
There is a segment that answers your question:
[[ $a == z* ]] # True if $a starts with an "z" (pattern matching).
[[ $a == "z*" ]] # True if $a is equal to z* (literal matching).
[ $a == z* ] # File globbing and word splitting take place.
[ "$a" == "z*" ] # True if $a is equal to z* (literal matching).
So in your case the condition should be:
if [[ file != te* ]]

Using CVS diff to get line numbers of mofied/added/deleted code

I have a very large project where we have made changes to lots of files. Now we need to exactly know which line numbers we have changed/added so that we can run some other tool on that particular line only.
While searching for the answer i found this as an answer to some other question..
echo ${f}:
for n in $(git --no-pager blame --line-porcelain $1 |
awk '/author Not Committed Yet/{if (a && a !~ /author Not Committed Yet/) print a} {a=$0}' |
awk '{print $3}') ; do
if (( prev_line > -1 )) ; then
if (( "$n" > (prev_line + 1) )) ; then
if (( (prev_line - range_start) > 1 )) ; then
echo -n "$range_start-$prev_line,"
else
echo -n "$range_start,$prev_line,"
fi
range_start=$n
fi
else
range_start=$n
fi
prev_line=$n
done
if (( "$range_start" != "$prev_line" )) ; then
echo "$range_start-$prev_line"
else
echo "$range_start"
fi
And it ends up looking like this:
views.py:
403,404,533-538,546-548,550-552,554-559,565-567,580-582
It does great.. i need the exact same output using cvs.. Is there any way to get similar output..

How to make zsh vi-style commands respect WORDCHARS?

I prefer vi-style word movements such as vi-forward-word instead of forward-word, so that the cursor also stops on separator characters. However, I would also like to make zsh respect WORDCHARS in this case or somehow define my separator characters. Is this possible somehow? It seems I can either make zsh use my separator characters, or use vi-style movements where it also stops on them, but not both.
So e.g. if my line is the following:
% ls -la /foo/bar/f-b/r
then if I start moving forward word by word, it will stop on /, foo, /, bar, /, f-b, /, r.
Relevant lines from my .zshrc:
WORDCHARS='*?_-.[]~=&;!#$%^(){}<>' # removed /
autoload select-word-style
select-word-style normal
bindkey '^W' vi-backward-kill-word
bindkey '^f' vi-forward-word
bindkey '^b' vi-backward-word
In the end I just implemented my own zle widgets:
SEPCHARS='[/ ]'
my-forward-word() {
if [[ "${BUFFER[CURSOR + 1]}" =~ "${SEPCHARS}" ]]; then
(( CURSOR += 1 ))
return
fi
while [[ CURSOR -lt "${#BUFFER}" && ! "${BUFFER[CURSOR + 1]}" =~ "${SEPCHARS}" ]]; do
(( CURSOR += 1 ))
done
}
zle -N my-forward-word
bindkey '^f' my-forward-word
my-backward-word() {
if [[ "${BUFFER[CURSOR]}" =~ "${SEPCHARS}" ]]; then
(( CURSOR -= 1 ))
return
fi
while [[ CURSOR -gt 0 && ! "${BUFFER[CURSOR]}" =~ "${SEPCHARS}" ]]; do
(( CURSOR -= 1 ))
done
}
zle -N my-backward-word
bindkey '^b' my-backward-word
my-backward-kill-word() {
if [[ "${LBUFFER[CURSOR]}" =~ "${SEPCHARS}" ]]; then
LBUFFER="${LBUFFER[1, CURSOR - 1]}"
return
fi
while [[ CURSOR -gt 0 && ! "${LBUFFER[CURSOR]}" =~ "${SEPCHARS}" ]]; do
LBUFFER="${LBUFFER[1, CURSOR - 1]}"
done
}
zle -N my-backward-kill-word
bindkey '^W' my-backward-kill-word