backspace not working in bash restricted mode - linux

I am facing a problem with backspace in bash when used in restricted mode. I have already googled through lots of things, nothing worked or matching scenario am facing.
On pressing backspace, cursor is moving forward by one white space, but internally actually it's deleting the previous letter, i.e. on pressing "enter" it actually works but not visible on screen.
Example: command "ls backspace backspace", don't list anything (as expected) but on screen ls is visible after 2 backspaces and extra 2 white spaces are appended.
Looking forward for helpful suggestions. :)
Thanks in advance !! :)
Below is the piece of patch i used to chroot my bash.
Please have look and notify me if something is wrong here.
file: shell.c: ## -384,6 +387,30 ##
+ if (getcwd(pwd,sizeof(pwd)) != pwd )
+ {
+ return -1;
+ }
+ /* chroot to mount point path */
+ if( !(chroot(chroot_dir)))
+ {
+ seteuid(getuid());
+ setegid(getgid());
+ /* On successful to chroot env invoke bash prompt */
+ if(! chdir(pwd))
+ {
+ if(execlp("/rbin/bash","/rbin/bash","--restricted",NULL))
+ {
+ }
+ }
+ else
+ {
+ chdir("/");
+ if(execlp("/rbin/bash","/rbin/bash","--restricted",NULL))
+ {
+ }
+ }
+ }

Try using Backspace with Shift key, It should work.
If pressing backspace is printing a character, then you can use stty to change terminal settings like this: stty erase backspace_character where backspace_character is the character you get while pressing backspace.

you can use emacs command
for shell terminal you can hit command as below
set -o emacs
for vi editor you can hit command as below
set -o vi

Related

Expand Command Line Arguments Autohotkey

TLDR; I am trying to find an equivalent to bash $# in autohotkey
I am developing an autohotkey script which will run a specific program when triggered.
<^#i::Run D:\Scripts\myprog.exe "arg_1" "arg_2"
; Runs with whatever arguments I provide on pressing Ctrl + Win + I
I want the program to be started with specific command line arguments; that I provide during starting the script.
> ahk_prog.exe arg_1 arg_2
I basically want to be able to convert my command line arguments provided during starting the program to be able to run the Run Command every time I trigger it.
I tried this:
<^#i::Run D:\Scripts\myprog.exe %A_Args% ; A_Args is the array of CLI arguments
; Runs with whatever arguments I provide on pressing Ctrl + Win + I
I also tried this(this one does not compile at all)
<^#i::Run D:\Scripts\myprog.exe "%*%" ; Trying Batch Like syntax since %1% and %2% are valid
; Runs with whatever arguments I provide on pressing Ctrl + Win + I
Both of them do not work. Is there a way to do this?
A_Args(docs) is an array, so you'll have join it into a string.
For example:
for each, arg in A_Args
arg_list .= """" arg """ "
arg_list := RTrim(arg_list) ;trim trailing space (might be unnecessary)
MsgBox, % arg_list
Added quotes around the argument, since they will of course be needed if your argument has spaces in it.
Then you can add it to your Run command like so:
for each, arg in A_Args
arg_list .= """" arg """ "
arg_list := RTrim(arg_list) ;trim trailing space (might be unnecesary)
<^#i::Run, % "D:\Scripts\myprog.exe " arg_list
Could also be done as a one-liner like so:
<^#i::Run, % "D:\Scripts\myprog.exe " RTrim(Format(StrReplace(Format("{:0" A_Args.length() "}", ""), 0, """{}"" "), A_Args*))

Vim command to go past a closing ) } ] " ' without pressing right arrow?

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

Qt run shell on terminal

I need to run shell from Qt application in mac
QString strProcess = "/bin/bash ";
strProcess += (QDir::currentPath() + "/../../../apk_build.sh");
strProcess += " -a " + ui->textEdit_apk->toPlainText();
strProcess += " -o " + ui->textEdit_out->toPlainText();
strProcess += " -c " + ui->textEdit_channel->toPlainText();
QProcess process;
process.execute(strProcess);
here some problem.
problem 1: it can not show content info in terminal , I need to see running info.
problem 2: it can not find apktool: command not found. apktool can be find if I execute command in terminal without Qt Application(apktool path: /usr/bin/apktool).
Problem1
If you want just to save output of the process then just set standard output of process.
void QProcess::setStandardOutputFile ( const QString & fileName, OpenMode mode = Truncate )
If you want to get output in real time then you have to handle your process as standard sequential I/O device by calling read (), readLine () functions.
Problem 2
You have to load environment variable of you user. Try to:
source /etc/profile

Which error format should be used for Vim and Cppcheck?

I use the following script to integrate Cppcheck with gVim:
" vimcppcheck.vim
" ===================================================================
" Code Checking with cppcheck (1)
" ===================================================================
function! Cppcheck_1()
set makeprg=cppcheck\ --enable=all\ %
setlocal errorformat=[%f:%l]:%m
let curr_dir = expand('%:h')
if curr_dir == ''
let curr_dir = '.'
endif
echo curr_dir
execute 'lcd ' . curr_dir
execute 'make'
execute 'lcd -'
exe ":botright cwindow"
:copen
endfunction
:menu Build.Code\ Checking.cppcheck :cclose<CR>:update<CR>:call Cppcheck_1() <cr>
Normally this is very good, but this script sometimes creates trouble when checking wrong pointers with Cppcheck.
For example, I have the following C code:
/* test_cppcheck.c */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int *ptr01;
*ptr01 = (int *)malloc((size_t)10 * sizeof(int)); /* FIXME: I intensionally written *ptr01 instead of ptr01 */
if(ptr01==NULL) {
fprintf(stderr, "\ndynamic memory allocation failed\n");
exit(EXIT_FAILURE);
}
free(ptr01);
ptr01 = NULL;
}
The quickfix list shows:
|| Checking test_cppcheck.c...
H:\codes\test_cppcheck.c:11] -> [test_cppcheck.c|12| (warning) Possible null pointer dereference: ptr01 - otherwise it is redundant to check it against null.
H:\codes\test_cppcheck.c|11| (error) Uninitialized variable: ptr01
H:\codes\test_cppcheck.c|16| (error) Uninitialized variable: ptr01
H:\codes\test_cppcheck.c|12| (error) Uninitialized variable: ptr01
|| Checking usage of global functions..
|| (information) Cppcheck cannot find all the include files (use --check-config for details)
After a lot of Vim errors, a new file '11] -> [test_cppcheck.c' is created in a new buffer. When I double-click the first error, nothing can be done from the quickfix window. It is because of the errorformat as much as I know.
The -> instead of : is creating all the trouble, although I know minor tweaking of this script will fix this issue, but I am tired of doing so.
Please try this first. How can I deal with this?
Without the original format of the error this is guesswork, but I think you need to add an alternative to the 'errorformat' definition (these are comma-separated):
setlocal errorformat=[%f:%l]\ ->\ %m,[%f:%l]:%m
PS: You should also use :setlocal for the 'makeprg' option to restrict it to the current buffer, too.
Now I'm using the script below, and it's working perfectly as I expected.
This can be a general solution to everyone who is interested to integrate Cppcheck with Vim.
Of course, this script can be improved a lot. But it's a starting point for them.
" vimcppcheck.vim
" ===================================================================
" Code Checking with cppcheck (1)
" Thanks to Mr. Ingo Karkat
" http://stackoverflow.com/questions/19157270/vim-cppcheck-which-errorformat-to-use
" ===================================================================
function! Cppcheck_1()
setlocal makeprg=cppcheck\ --enable=all\ %
" earlier it was: " setlocal errorformat=[%f:%l]:%m
" fixed by an advise by Mr. Ingo Karkat
setlocal errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m
let curr_dir = expand('%:h')
if curr_dir == ''
let curr_dir = '.'
endif
echo curr_dir
execute 'lcd ' . curr_dir
execute 'make'
execute 'lcd -'
exe ":botright cwindow"
:copen
endfunction
:menu Build.Code\ Checking.cppcheck :cclose<CR>:update<CR>:call Cppcheck_1() <cr>

VIM: Check if a file is open in current tab? window? (and activate it)

In vim, you can check if a file is open in the current buffer with bufexists. For a short filename (not full path), you can check if it's open using bufexists(bufname('filename')).
Is there any way to check if a file is open in a tab?
My closest workaround is to do something like:
:tabdo if bufnr(bufname('filename')) in tabpagebuflist(): echo "Yes"
However, that's sort of pythonic pseudocode... I'm not sure how to get that to work in vim. My goal is for an external applescript to check if a file is already open and if so go to a line in that file.
Ideally, I'd like to be able to search through different GUI windows too, but I've gathered (e.g. Open vim tab in new (GUI) window?) that working with different GUI windows is very challenging / impossible in VIM.
My impatience and good documentation got the better of me... here's the solution (greatly aided by Check if current tab is empty in vim and Open vim tab in new (GUI) window?). The source is at https://github.com/keflavich/macvim-skim
function! WhichTab(filename)
" Try to determine whether file is open in any tab.
" Return number of tab it's open in
let buffername = bufname(a:filename)
if buffername == ""
return 0
endif
let buffernumber = bufnr(buffername)
" tabdo will loop through pages and leave you on the last one;
" this is to make sure we don't leave the current page
let currenttab = tabpagenr()
let tab_arr = []
tabdo let tab_arr += tabpagebuflist()
" return to current page
exec "tabnext ".currenttab
" Start checking tab numbers for matches
let i = 0
for tnum in tab_arr
let i += 1
echo "tnum: ".tnum." buff: ".buffernumber." i: ".i
if tnum == buffernumber
return i
endif
endfor
endfunction
function! WhichWindow(filename)
" Try to determine whether the file is open in any GVIM *window*
let serverlist = split(serverlist(),"\n")
"let currentserver = ????
for server in serverlist
let remotetabnum = remote_expr(server,
\"WhichTab('".a:filename."')")
if remotetabnum != 0
return server
endif
endfor
endfunction
then use like so:
exec "tabnext ".WhichTab('my_filename')
echo remote_foreground( WhichWindow('my_filename') )
or, from the command line, here's a script to go to a particular line of a file using WhichTab:
#!/bin/bash
file="$1"
line="$2"
for server in `mvim --serverlist`
do
foundfile=`mvim --servername $server --remote-expr "WhichTab('$file')"`
if [[ $foundfile > 0 ]]
then
mvim --servername $server --remote-expr "foreground()"
mvim --servername $server --remote-send ":exec \"tabnext $foundfile\" <CR>"
mvim --servername $server --remote-send ":$line <CR>"
fi
done
I'd reply to keflavich, but I can't yet...
I was working on a similar problem where I wanted to mimic the behavior of gvim --remote-tab-silent when opening files inside of gvim. I found this WhichTab script of yours, but ran into problems when there is more than one window open in any given tab. If you split windows inside of tabs, then you will have more than one buffer returned by tabpagebuflist(), so your method of using the buffer number's position in the List doesn't work. Here's my solution that accounts for that possibility.
" Note: returns a list of tabnos where the buf is found or 0 for none.
" tabnos start at 1, so 0 is always invalid
function! WhichTabNo(bufNo)
let tabNos = []
for tabNo in range(1, tabpagenr("$"))
for bufInTab in tabpagebuflist(tabNo)
if (bufInTab == a:bufNo)
call add(tabNos, tabNo)
endif
endfor
endfor
let numBufsFound = len(tabNos)
return (numBufsFound == 0) ? 0 : tabNos
endfunction
I think I can just return tabNos which will be an empty list that gets evaluated as a scalar 0, but I just learned vimscript and am not that comfortable with the particulars of its dynamic typing behavior yet, so I'm leaving it like that for now.

Resources