How do I copy current folder name to the command line of Midnight commander? - mc

I need something similar to ctrl+enter in total commander, copy current selected folder name in the panel to the command line

In some terminals (default configuration of Windows Terminal) you cannot use:
Alt+something combinations
modifier+Enter combinations
For such cases there are these sequences:
Esc, Enter or Ctrl+x, (Ctrl+)t --- copy the file (dir) name from the cursor to the command line
Esc, a or Ctrl+x, (Ctrl+)p --- copy the panel's directory path to the command line

Try the shortcut:
Left Alt + Enter

The following combination does this: Alt+Shift+Enter

Related

How to start explorer.exe with QProcess when the path to the specified file contains spaces?

I want to start explorer and select a specific file. So I run
QProcess::startDetached(command);
with command set to
explorer.exe /select,C:\Users\....\file.txt
This works fine, but will fail if the path to the file contains spaces. But if I put the path in quotes
explorer.exe /select,"C:\Users\....\file.txt"
the explorer will open the documents folder and not the specified path.
Running the same string from the command line works fine.
The string is initialized with
command = "explorer.exe" + "/select," + "\"" + QDir::toNativeSeparators(path) + "\"";
How to achieve this is indeed not so intuitive, but also not impossible.
Solution
Decompose all arguments of the command, explorer.exe, as separate strings, i.e. /select, ,, the_path.
Example
QProcess::startDetached("explorer.exe", QStringList{"/select", ",", "C:\\Users\\Your Username\\Desktop\\Folder With Spaces\\file.txt"});

Trace32 Write directory location to file

So I finally decided to bite the bullet and rewrite my company's terrible Trace32 scripts. I'm trying to use a data file to save the pertinent information between runs so we can just run a Redo script to repeat any action without having to navigate a mess of dialog boxes and select our workspace files after every power cycle. In order to do this, I will need to save the user defined variables from the previous run (including file locations) to file so I have them in the next run. For reference, here is a part of my menu script.
; File: Do.cmm
GLOBAL &WORKSPACE
GLOBAL &FILETOLOAD
GLOBAL &TARGETSELVAL
&WORKSPACE="//tsclient\Z\Product_trunk_MS" ; Not the ideal solution
PRINT "Workspace is &WORKSPACE"
DIALOG
(
HEADER "Do one of the following"
POS 0. 0. 23.
COMMAND.PREVIOUS: CHOOSEBOX "Repeat Last Command" ""
POS 24. 0. 23.
COMMAND.WORKSPACE: CHOOSEBOX "Change Workspace Location" ""
POS 0. 3. 25.
TEXT "Connect To an R7 Proc:"
POS 0. 4. 6.
COMMAND.IP0: CHOOSEBOX "IP0" ""
POS 8. 4. 7.
COMMAND.IP1: CHOOSEBOX "IP1" ""
; And a lot more of the same...
POS 17. 16. 15.
DEFBUTTON "OK" "continue"
)
DIALOG.SET COMMAND.PREVIOUS
STOP
IF DIALOG.BOOLEAN(COMMAND.IP0)
(
&TARGETSELVAL=0x00030000
&FILETOLOAD="&WORKSPACE\CPUs\IP0\build\output\IP0.axf"
)
IF DIALOG.BOOLEAN(COMMAND.IP1)
(
&TARGETSELVAL=0x0003001
&FILETOLOAD=&WORKSPACE\CPUs\IP1\build\output\IP1.axf
)
... And so on
The problem with this is that I have to edit the script every time I change workspaces. I want to be able to set this in the script above by selecting COMMAND.PREVIOUS and then selecting my new workspace root with the Windows selection dialog. I don't have a working implementation for that function, but I want it to look something like this:
IF DIALOG.BOOLEAN(COMMAND.WORKSPACE)
(
PRINT "Select the new root directory that you would like to work out of."
OPEN #1 workspace.dat /Create
&WORKSPACE= C/*/ ; I don't know how to do this here.
WRITE #1 &WORKSPACE
CLOSE #1
ENDDO
)
Obviously, Data.load.binary "*.bin" is able to load a file to memory, but I don't need the file loaded yet, I just want the path. I did find that symbol.SOURCEPATH.SETBASEDIR c:\* will open a dialog box, but I am still having trouble getting at that information.
Additional Info
I have read through a lot of this and this while trying to find a solution. If there is a built in path variable that I should be using (like the aforementioned SOURCEPATH.SETBASEDIR, I wouldn't mind doing that instead. This is my first day writing Trace32 scripts, so I apologize in advance for my naivete. If it matters, I am using Trace32 Powerview for ARM Release Feb 2017 SP2 (32 bit) (So, the latest)
TRACE32 has the concept of a working directory. The command ChDir can be used to change the current directory:
ChDir <path>
The current working directory can be retrieved with the PRACTICE function OS.PWD():
&WORKSPACE=OS.PWD()
The script example above could be extended like this:
IF DIALOG.BOOLEAN(COMMAND.WORKSPACE)
(
PRIVATE &old_directory
&old_directory=OS.PWD() // Save current directory
ChDir * // Open directory selection dialog
&WORKSPACE=OS.PWD() // Update working directory
OPEN #1 workspace.dat /Create
WRITE #1 &WORKSPACE
CLOSE #1
ChDir &old_directory // Restore previous directory selection
)
I ended up finding a solution to my problem that was a little different than xasc's, so I thought I'd share it.
IF DIALOG.BOOLEAN(COMMAND.WORKSPACE)
(
PRINT "Select the new root directory that you would like to work out of."
DIALOG.DIR *
ENTRY %LINE &WORKSPACE
OPEN #1 workspace.dat /Create
WRITE #1 "&WORKSPACE"
CLOSE #1
)
This was a little cleaner for my purposes because it didn't require me to change the working directory.
DIALOG seems to be the interface I was looking for, with the ability to open files, directories, and more and save them into variables.

When using zeus in zsh cursor position shifts after the the termination of zeus command

Sometimes there is a strange issue with terminal cursor in zsh when zeus command was terminated.
The position of cursor shifts and each line of the output in the console has extra indentation, e.g.
services GET /services(.:format) services#index
payments GET /payments(.:format) payments#index
orders_verify POST /orders_verify(.:format) orders_verify#index
orders GET /orders(.:format) orders#index
diets GET /diets(.:format) diets#index
The only way to fix that is to open a new terminal window/tab
Staircasing is unrelated to locale. Full-screen programs manipulate the terminal-mode settings to let them read single characters from the screen as well as send special characters (such as carriage return and line-feed) to the screen without having the terminal driver "translate" them.
The quick fix — run this command:
reset
(you may have to press controlJ after typing "reset" to enter this properly)
Further reading:
tset, reset - terminal initialization
Make sure you have set LOCALE environment vars to UTF-8 in your .zshrc file
Open .zshrc
vim ~/.zshrc
Add these lines
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Close the file (Shift-ZZ) and reload it in the current session (or open a new terminal window/tab)
. ~/.zshrc

sublimerepl getenv failing

I'd like to use the SiblimeREPL package with Sublime Text. When I try to start a REPL, I get
SublimeREPL: obtaining sane environment failed in getenv()
Check console and 'getenv_command' setting
WARN: Falling back to SublimeText environment
This happens regardless of which REPL I try to start. (I tried Ruby, Python, and Clojure.) I tried Sublime Text 2 and Sublime Text 3 with the same results. This is on Mac OS X, if that matters.
I looked in the package settings, where I see
"getenv_command": ["/bin/bash", "--login", "-c", "env"],
If I run "/bin/bash --login -c env" at a Terminal prompt, I get my environment listed.
What do I need to change in order to get a successful getenv_command?
I had the same problem as ssgam. The problem line for me is in the getenv method. It calls subprocess.check_output(getenv_command), which doesn't exist in python 2.6, which ST2 seems to use.
The trick is, it only calls subprocess.check_output() if getenv_command is truthy, and defaults to os.environ.copy() otherwise. So to get ssgam's fix without modifying the SublimeREPL package, in Preferences > Package Settings > SublimeREPL > Settings - User, do something like this:
{
"getenv_command": false
}
I investigated this issue a little bit deeper and it seems SublimeText 3 is also affected. In my case the problem is related to bash-completion feature, in particular COMP_WORDBREAKS environment variable.
Use the following command to show the contents of COMP_WORDBREAKS:
$ echo "$COMP_WORDBREAKS"
will output
"'><=;|&(:
You can also use:
$ echo $COMP_WORDBREAKS
but note that with the second command (without quotes), you'll not see that
the variable also contains a line feed character.
The problem here is the line feed character which breaks output parsing in getenv_command feature. If you extract part of the source code for SublimeREPL you can get real error message from python interpreter.
Traceback (most recent call last):
File "main.py", line 71, in getenv
env = dict(line.split('=', 1) for line in lines)
ValueError: dictionary update sequence element #6 has length 1; 2 is required
You can match element #6 with the position of COMP_WORDBREAKS in env listing.
Solution (first that came to my mind)
I can't tell at the moment what is real impact on bash-completion feature after following solution is applied and of course SublimeREPL hopefully should be fixed accordingly. Please comment my answer to fill in missing knowledge.
We may want to remove disturbing characters to get rid of the error.
First let's identify those characters
$ echo -n "${COMP_WORDBREAKS}" | od -t x1c
will output
0000000 20 09 0a 22 27 3e 3c 3b 7c 26 28 3a
\t \n " ' > < ; | & ( :
0000014
so we have three to remove. The simplest way is to add to your .bashrc following line:
COMP_WORDBREAKS="${COMP_WORDBREAKS#???}"
Voila! No more error message.
My final thought is about removed characters. I'm not fully in how bash-completion works and I'm aware of that modifying COMP_WORDBREAKS can affect other scripts using it. For now you can always change it ad-hoc.
I hope this helped.
Cheers
Found it. Fixed it. SublimeREPL assumes that running getenv_command will produce SOLELY the output from running env, and every line will contain an equals sign. But my .bash_profile echos some stuff to stdout.
The solution was to wrap my .bash_profile output in a
if [[ $- == *i* ]]
to not produce extra output besides the executed command.
TLDR;
Replace:
env = dict(line.split('=', 1) for line in lines)
in ~/.config/sublime-text-3/Packages/SublimeREPL/repls/subprocess_repl.py with
env = dict(line.split('=', 1) for line in lines if '=' in line)
(Thanks #MichaelOhlrogge for the shorter syntax)
Why this works
#develucas's solution helped me solve my issue. I didn't have the problem he was describing, but his investigation helped.
In my case, the login shell had a greeting. So, bash --login -c env (the command specified in SublimeREPL.sublime-settings file under the getenv_command option) was printing something like this:
Hello, parth!
USER=parth
SHELL=/bin/bash
.
.
.
It turns out that SublimeREPL uses the output of this command to load the environment variables - as mentioned in the comment above the getenv_command setting:
// On POSIX system SublimeText launched from GUI does not inherit
// a proper environment. Often leading to problems with finding interpreters
// or not using the ones affected by changes in ~/.profile / *rc files
// This command is used as a workaround, it's launched before any subprocess
// repl starts and it's output is parsed as an environment
"getenv_command": ["/bin/bash", "--login", "-c", "env"],
The code that parses this output is like this (in the ~/.config/sublime-text-3/Packages/SublimeREPL/repls/subprocess_repl.py file for ST3):
def getenv(self, settings):
"""Tries to get most appropriate environent, on windows
it's os.environ.copy, but on other system's we'll
try get values from login shell"""
getenv_command = settings.get("getenv_command")
if getenv_command and POSIX:
try:
output = subprocess.check_output(getenv_command)
lines = output.decode("utf-8", errors="replace").splitlines()
env = dict(line.split('=', 1) for line in lines)
return env
except:
import traceback
traceback.print_exc()
error_message(
"SublimeREPL: obtaining sane environment failed in getenv()\n"
"Check console and 'getenv_command' setting \n"
"WARN: Falling back to SublimeText environment")
# Fallback to environ.copy() if not on POSIX or sane getenv failed
return os.environ.copy()
The env = dict(line.split('=', 1) for line in lines) line causes an issue, because the first line in the bash --login -c env output has no =. So I modified this line to ignore the lines that don't have an = sign:
env = dict(line.split('=', 1) for line in lines if '=' in line)
And this solved the issue for me. Don't forget the restart Sublime Text after modifying this file.
changing COMP_WORDBREAKS does not work for me ...
i'm using ST2, and the exception was thrown at check_output().
also, name completions at the command line fails, after changing COMP_WORDBREAKS.
in my case, i changed subprocess_repl.py's env() method:
[wind]$ diff subprocess_repl.py.20151117.173317 subprocess_repl.py
160c160,161
< updated_env = env if env else self.getenv(settings)
---
> # updated_env = env if env else self.getenv(settings)
> updated_env = env if env else os.environ.copy()
[wind]$
would be interesting to find out why the problem started appearing suddenly ...
hth,cheers,
sam
The answer from #develucas mostly works for me with ST3 with OSX El Capitan except I had to put
export COMP_WORDBREAKS="${COMP_WORDBREAKS#???}"
Note the export. However, if I do this, tab completion no longer works.
I had the same problem, it was my .bash_profile that had some utility outputs, such as a welcome message etc.
These outputs are parsed by SublimeREPL to try to extract environment variables from the output of the env command, and the extraneous text lines mixed together provoked the error.
(I'd like to make a PR to SublimeREPL to try to make that phase more robust, it should not depend on particular .bash_profile implementations!)

How to remove file name from cmd NOTEPAD /P

I have a command line being executed in my C++ code that states:
CString sCmd = "NOTEPAD /P myfile.txt";
WinExec(sCmd, SW_HIDE);
The file prints out but at the top of each page is the text, centered, "myfile.txt", next line the beginning of my file text.
Is there a way to eliminate the file title on each page of the print out and/or at least but a blank line between the title and the beginning of the text?
Thanks
This seems like an example of an XY problem.
There is no command line option for Notepad that will change or remove the page header. Notepad will remember your configured page settings though, so you could start Notepad manually, set header and footer in Page Setup, quit, then program will print using your presets.
Or, why not just use the Windows print console tool, instead of Notepad?
WinExec("cmd.exe /c print /d:\\servername\printername filename.txt", SW_HIDE);