How to use current file as parameter to Run configuration in pycharm - intellij-idea

I want to create custom run configurations, but i cannot figure out how to get the current file name as a parameter...
I would like to do something like this:
py.test -m mymarker %f
autopep8 %f
where %f is the current file name.

The answer by Ctrl+C already hints at $FileName$ and at least in the current version 2020.2 of PyCharm this works in Run Configurations.
Create a run configuration as you desire, e.g. Python
In Parameters field you can simply use macros like $FileName$ or $FilePath$. Or click on the + at the right end for a full list
Hit the Run button or Shift+F10 by default while your target file is opened

What you want to insert there is called a macro, which is a context-dependent variable: $FileName$ (current file in this case). Unfortunately this doesn't work yet in Run configurations.
Workaround - use External Tools
Settings > Tools > External Tools
[+]
set "Program" as path to your script/program ('py.test')
in "Arguments" use button [Insert Macro...] on the right. There will be a list of possibilities. For example you wanted $FileName$ for the current file.
If you want both of those commands in one External Tool command, then create a bash script:
#!/bin/bash -exu
py.test -m mymarker $#
autopep8 $#
Finally you can use it via [Tools]>[External Tools], [Right click on a file]>[External Tools] or you can add a shortcut to the command.

I solved similar problems with Ruby as shown in screenshot link below.
After that: right click on script-file, select in Pop-up menu External Tools -> [Your runner]

Related

Cant start linux "screen" with logging to specific output file

I have the problem that I want to enable logging of a screen session at the start of it which then saves the log to a specific file.
What I have until now was:
screen -AmdSL cod2war /home/cod2server/scripts/service_28969.sh
while service_28969.sh is a shell script that will call other scripts which produce output.
I started multiple of those screen-sessions with different names, for example
screen -AmdSL cod2sd /home/cod2server/scripts/service_28962.sh
-L enables logging as the screen's man say, and will safe the ouput in a file called 'screenlog.0', now since I have multiple of those screens only one of it produces output saved in that log file (I can't find other 'screenlog.*' files in that folder).
I thought to use the -Logfile "file" option from the same man page, but it doesn't work for me and I can't find out what I'm doing wrong..
screen -Logfile cod2sd.log -AmdS cod2sd /home/u268450/cod2server/scripts/service_28962.sh
will produce the following error:
Use: screen [-opts] [cmd [args]]
or: screen -r [host.tty]
Options:
[...]
Error: Unknown option Logfile
and
screen -AmdS cod2sd /home/u268450/cod2server/scripts/service_28962.sh -Logfile cod2sd.log
will run without any error and start the screen but without the logging at all..
You can specify a logfile from within the default startup ~/.screenrc file using a line like
logfile mylog.log
To do this from the command line you can create a file mystartup to hold the above line, then use option -c mystartup to tell screen to read this file for setup instead of the default. If you also need to have ~/.screenrc read, you can add the source command to your startup file. The final result would look something like:
echo 'logfile mylog.log
source ~/.screenrc' >mystartup
screen -AmdSL cod2war -c mystartup /home/cod2server/scripts/service_28969.sh
This works for me:
screen -L -Logfile /Logs/Screen/`date +%Y%m%d`_screen.log
The configs I checked:
screen version 4.08.00 (GNU) 05-Feb-20 on FreeBSD 12.2
and
version 4.06.02 (GNU) 23-Oct-17 on Debian GNU/Linux 10 (buster)
and
version 4.00.03 (FAU) 23-Oct-06 on Mac OS X 10.9.5.
I just ran into this error myself and found this solution that worked with my python file, wanted to share for anyone else who might run into this issue:
screen -L -Logfile LOGFILENAME.LOG -dmS SCREENNAME python3 ./FILENAME.PY
I have no idea if this is the 'correct' way but it works.
-L enables logging
-Logfile LOGFILENAME.LOG declares what to call the log file and file format
-dmS SCREENNAME, dm runs in detached mode and S allows you to name the session
python3 ./FILENAME.PY in this case is my script but I assume that any other script here functions
I have tried a different ordering of these commands and this was the only way I managed to have them all run without issues. Hopes this helps.

Vue-cli: arrow key not working while creating new project on git bash windows

I am trying to create a project which Vue-cli through Git bash Window.
Git version 2.14.1.windows.1
Vue version 3.0.0-rc.3
For some reason the cursor is still visible during installation.
And when I press any arrow key, the option does not change, only the cursor move around. (However, pressing enter still process me to the next step).
Searching for a solution with google does not let me anywhere, only a few Github bug report: https://github.com/vuejs/vue-devtools/issues/283
I had the same issue. The solution I came up with was:
$ winpty vue.cmd create `<project-name>`
Surprisingly, Windows Command Prompt is not suffered from this bug. So my solution is:
Hold Shift + Right click project folder -> choose Open command window here
This does not solve the root cause. If you happen to know a better option, please post your answer.
Note:
If you get error cannot execute scripts on powershell, then you need to enable script execution. Run powershell as administrator and run the following command to enable scripts on it:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
UPDATED 2021, Apr 4th!
Here's a CTRL+C and CTRL+V step-by-step practical solution to solve this. The fact that you have this trouble means you are on Windows and you most likely use Git Bash.
Using Git Bash a quick solution would be typing
echo 'alias vue="winpty vue.cmd"' >> ~/.bashrc
This will not overwrite .bashrc, and instead append the text on the left of >>
Restart your bash. That means close it and open it again.
If you're looking for "Why do I have to add such thing to .bashrc?", I think another user has mentioned that. If you found this helpful please upvote it so others can see it too.
Old answer
You can try to make a file .bashrc in your current <UserNameProfile>.
Then, inside of it use your favourite text editor and write
alias vue='winpty vue.cmd'
Then restart your bash. And you should be able to use vue as it should be on the documentation.
There are two ways to solve this issue which is explained in the Vue CLI Documentation:
1 - You must run the command as winpty vue.cmd create hello-world.
2 - If you still want to use the vue create hello-world syntax. You'll need to add the following line, alias vue='winpty vue.cmd', to your ~/.bashrc file. Then, you'll need to restart your Git Bash terminal session to pull in the updated bashrc file.
Git Bash is not an interactive shell. That's why you should use something that is by default interactive such as CMD or you have to do as mentioned in the Vue CLI doc:
If you are on Windows using Git Bash with minTTY, the interactive
prompts will not work. You must launch the command as winpty vue.cmd
create hello-world. If you however want to still use the vue create
hello-world syntax, you can alias the command by adding the following
line to your ~/.bashrc file. alias vue='winpty vue.cmd' You will need
to restart your Git Bash terminal session to pull in the updated
bashrc file.
Vue CLI is an interactive CLI. But Git Bash is not an interactive shell. That's why it won't work. Source

ConEmu + WSL: Open new console in current tab directory

I'm using WSL and ConEmu build 180506. I'm trying to setup a task in ConEmu to use the current directory of the active tab when opening a new console but I cannot get it to work.
What I did is to setup the task {Bash: bash} using the instructions on this page
setting the task command as :
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -C~ -cur_console:pm:/mnt
Then following the instruction on this page, I added to my .bashrc
if [[ -n "${ConEmuPID}" ]]; then
PS1="$PS1\[\e]9;9;\"\w\"\007\e]9;12\007\]"
fi
and finally setup a shortcut using the macro :
Shell("new_console", "{bash}", "", "%CD%")
But it always open the new console in the default directory ('/home/[username]').
I don't understand what I'm not doing right.
I also noticed that a lot of environment variables listed here are not set. Basically, only $ConEmuPID and $ConEmuBuild seem to be set.
Any help would be appreciated.
GuiMacro Shell was intended to run certain commands, not tasks.
You think you may try to run macro Task("{bash}","%CD%")
Or set your {bash} task parameters to -dir %CD% and just set hotkey for your task.
Of course both methods require working CD acquisition from shell. Seems like it's OK in your case - %d shows proper folder.
I found the answer:
Shell("new_console:I", "bash.exe", "", "%CD%")
The readme is actually pretty good: https://github.com/cmderdev/cmder/blob/master/README.md

how can I install "elm-light" on windows?

elm-light looks like a great plugin for elm in the LightTable editor, but I can't make it work properly on Windows. When I try to establish a connection, I get this error : Path must be a string. Received null.
Please help...
"Path must be a string" should already be fixed in elm-light-0.42
AST
Auto-completions only starts working once you have connected to an Elm project. You can force "suto.connection", through various commands (Lint, toggle docs etc). So if you hit "ctrl-d" on a symbol when you aren't connected, it will connect for you. Another option is to add the Lint command to the save operation in Light Table. Again see Useful configurations
-- https://rundis.gitbooks.io/elm-light-guide/content/chapter1.html
After opening elm file in Light Table, you can see at the status: AST not connected. That means elm-light doesn't run yet.
You have to connect manually either by running ctrl+space > ELM: Load/reload project AST or better by mapping this action to save.
To do this, run ctrl-space > Settings: User keymap. Add line [:editor.elm "ctrl-s" :save :elm-format :elm.lint] before last ] so it looks like this:
[
;; ...
[:editor.elm "ctrl-s" :save :elm-format :elm.lint]
]
Above mapping to ctrl-s will also format and lint your file.
One more thing. If you type for example import Dict as Dict exposing (, AST will report error. For that we need to automatic brackets close. To do that, run ctrl-space > Settings: User behaviors and add line [:editor :lt.objs.editor/autoclose-brackets], so that the file looks like that:
[
;; ...
[:editor :lt.objs.editor/autoclose-brackets]
]
Avoid spaces in the path to the elm-platform
type echo %path% in a Windows command prompt to check the Elm path
uninstall and reinstall elm in another folder if necessary
Avoid spaces in the path to LightTable
move the LightTable folder if necessary
uninstall and reinstall the elm plugin in the new location
Install elm-oracle
execute npm install elm-oracle in a Windows command prompt to get auto-complete to work.
Install elm-format
Configure keymaps
use ctrl- (Windows) instead of cmd (iOS) in the keychords

Use dolphin (or other browser) like yakuake

I often want to open a file browser to open a file and then close the browser.
Is there a way (a plasmoid, a dolphin plugin, another browser...) which could allow me to have a file browser "in the style of" yakuake? (i.e. unfolding with a shortcut, and re-folding when I chose the file I want)
Took me some time, but finally managed to get what you want (and eventually, what I also want :) with xdotool (on Ubuntu sudo apt-get install xdotool).
With this script, you can have any application behave like you asked:
#!/bin/bash
SEARCHED_WINDOW=$1
COMMAND=${2:-$SEARCHED_WINDOW}
SEARCHED_WINDOW_CLASSNAME=toggleApp$SEARCHED_WINDOW
WINDOW_ID=$(xdotool search --classname $SEARCHED_WINDOW_CLASSNAME)
VISIBLE_WINDOW_ID=$(xdotool search --onlyvisible --classname $SEARCHED_WINDOW_CLASSNAME 2>/dev/null)
if [ -z "$WINDOW_ID" ]; then
$COMMAND 2>/dev/null &
pid=$!
NEW_WINDOW_ID=$(xdotool search --onlyvisible --sync --pid $pid 2>/dev/null)
xdotool set_window --classname $SEARCHED_WINDOW_CLASSNAME $NEW_WINDOW_ID
xdotool windowfocus $NEW_WINDOW_ID
elif [ -z "$VISIBLE_WINDOW_ID" ]; then
xdotool windowmap $WINDOW_ID
xdotool windowfocus $WINDOW_ID
else
xdotool windowunmap $VISIBLE_WINDOW_ID
fi
(Inspired from here)
You call it like this:
./toggle.sh dolphin
If the command to launch the program is different, you can add a second parameter:
./toggle.sh appName commandToLaunchApp
What this script does is the following:
If the app is not running: launch it, give window a specific class, and give window focus
If the app is running but with no visible window: make window visible and give it focus
Else, i.e. app is running and visible: hide it.
All you have left to do is map a shortcut to the above-mentionned command to launch the script. In KDE : System settings > Shortcuts and gestures > Custom shortcuts. Then Edit > New > Global shortcut > Command.
Plus, this script works with any app, should work with any EWMH compliant window manager, and allows you to have other instances of the same app (this is why I added the class trick).
The closest solution to what you want is the Widget Layer Compiz plugin.
This plugin enables you to make appear a layer on top of your workspace. You can configure this layer to hold windows of your choice, in your case that would be the file manager. It has a hide/show feature which you can bind to a hotkey.
It uses Window Matching rules to define the windows to hold.
More information on http://wiki.compiz.org/Plugins/Widget
However, this would imply that you use the Compiz compositing manager.