Is there any way to set a shortcut for frequently issued commands in Cmder? - automation

I use Cmder as my command prompt/console.
I find myself using the same commands many times a day. For example
git merge --no-ff my-long-branch-name
Is there any way I can store these commands in shortcut keys, like maybe, CTRL + G, instead of typing it each time?

Maybe it is a bit late, but still, here's the solution:
1) Open your Cmder folder and go to the config directory;
2) In \config\ open the file called aliases in any text editor;
3) Add this line at the end of the file:
my_alias_name=git merge --no-ff $*
4) Save the file and restart your Cmder;
5) Now you can type in your Cmder command line something like this:
my_alias_name my-long-branch-name
That's it :)
PS: Also, some information here can be useful for you.

Related

How to use alias for opening file from its absolute path in csh

I want to create an alias, which will take file name, get its path and open it by gvim.
Something like this:
alias gg "gvim `which \`"
usage:
> gg some_file_in_remote_path
But I cannot make it work in csh.
Can someone help please
The command "which" gets a full path of of shell commands.
It does not find the full path of of every file you have in your system.
The command you are looking for is "find", although searching the entire file system could be time consuming. Perhaps install "locate" and use that instead of find. Even then you would have to decide in your script what to do when multiple files have the same name.

Using intellij idea merge as default merge tool in hg

So, i've found this page here, showing how to use intellij's idea merge and diff from command line, and i'm trying to set it as a default for hg.
However, i still have some problems when merging branches (many files):
If hg merge is called while there's no idea instance running, it starts a new instance, show the diff, wait for my response (click on apply / abort). After that, it proceeds to the next file, and do the same. File by file. Works pretty well, but is also veery slow (since it needs to start a new instance every time). Also, as said, there must be no idea instance running, to do that.
If hg merge is called while an idea instance is running, it shows the first diff window, but at the same time starts to merge all other files... This end up in a lot of pop-ups of "file not found" on idea, pointing to tmp files (of .other and .original).
Does anybody know how to do that in a usable way? hg merge using idea merge as default ?
Here's my .hgrc file: [ui]
merge=idea
[merge-tools]
idea =
idea.gui = True
idea.args = merge $local $base $other $output
idea.priority = 1000
idea.premerge = False
Sorry for the bad english, and thanks to all in advance
Hi here are the settings I used successfully.
[ui]
merge=idea
[merge-tools]
idea.args = merge $local $other $base $output
Also ensure that idea is on the path.
My references are the mercurial MergeToolConfiguration and Merging files using IntelliJ IDEA as a command line tool.
Idea does not wait, but gives return too early. A good way to solve this problem is to get mercurial to prompt you.
By setting this configuration in the .hgrc
idea.check = prompt
Mercurial will ask for confirmation on each file. You must finish the merge in Idea before clicking "Yes" on the confirmation box.

IntelliJ: Dynamically updated file header

By default, IntelliJ Idea will insert (something like) the following as the header of a new source file:
/**
* Created by JohnDoe on 2016-04-27.
*/
The corresponding template is:
/**
* Created by ${USER} on ${DATE}.
*/
Is it possible to update this template so that it inserts the last date of modification when the file is changed? For example:
/**
* Created by JohnDoe on 2016-03-27.
* Last modified by JaneDoe on 2016-04-27
*/
It is not supported out of the box. I suggest you do not include information about author and last edit/create time in file at all.
The reason is that your version control system (Git, SVN) contains the same information automatically. So the manual labelling is just duplicate of already existing info, but is only more error prone and needs to be manually updated.
Here's a working solution similar to what I'm using. Tested on mac os.
Create a bash script which will replace first occurrence of Last modified by JaneDoe on $DATE only if the exact value is not contained in the file:
#!/bin/bash
FILE=src/java/test/Test.java
DATE=`date '+%Y-%m-%d'`
PREFIX="Last modified by JaneDoe on "
STRING="$PREFIX.*$"
SUBSTITUTE="$PREFIX$DATE"
if ! grep -q "$SUBSTITUTE" "$FILE"; then
sed -i '' "1,/$(echo "$STRING")/ s/$(echo "$STRING")/$(echo "$SUBSTITUTE")/" $FILE
fi
Install File Watchers plugin.
Create a file watcher with appropriate scope (it may be this single file or any other scope, so that any change in project's source code will update modified date or version etc.) and put a path to your bash script into Program field.
Now every time the file changes the date will update. If you want to update date for each file separately, an argument $FilePath$ should be passed to the script.
This might have been just a comment to #oleg-mikhailov excellent idea, but the code snippet won't fit. Basically, I just tweaked his solution.
I needed a slightly different syntax but that's not the issue. The issue was that when the script ran automatically upon file save using the File Watchers plugin, if ran on a file which doesn't include PREFIX it would run over and over for ever.
I presume the that the issue is with the plugin itself, as it didn't happen when run from the shell, but I'm not sure why it happened.
Anyway, I ended up running the following script (as I said only a slight change with respect to the original). The new script also raises an error if the the prefix doesn't exist. For me this is a feature as Pycharm prompts me with the error, and I can fix the file.
Tested with PyCharm 2021.2.3 on macOS 11.6.
#!/bin/bash
FILE=$1
DATE=`date '+%Y-%m-%d'`
PREFIX="last_modified_date: "
STRING="$PREFIX.*$"
SUBSTITUTE="$PREFIX$DATE"
if ! grep -q "$SUBSTITUTE" "$FILE"; then
if grep -q "$PREFIX" "$FILE"; then
sed -i '' "s/$(echo "$STRING")/$(echo "$SUBSTITUTE")/" $FILE
else
echo "Error!"
echo "'$PREFIX' doesn't appear in $FILE"
exit 1
fi
fi
PHPStorm has not a "hook" for launching task after detect a change in file (just for uploading in server yes). Code templating is based on the creation of file not change.
The behaviour you want (automatic change file after manual change file) can be useful for lot of things but it's circular headhache for editor. Because if you change a file it must change file (and if a file is change ? it change file ?).
However, You can, perhaps, "enable Live Templates" when you launch a "reformat code" which able to rewrite your begin template code that way rewrite date modification.
Other solution is that use a tools with as grunt but I don't know if manage php file.

Accurev: How to keep/promote with a multi line comment from the command line?

How to keep/promote with a multi line comment from the accurev command line?
For example if I try:
accurev stat -n -fl | xargs accurev keep -c "git log 1234..4311"
I simple get the error:
You can not use non-printable characters on the command line: # On
branch master\x0a... AccuRev was unable to understand your command.
I can of course strip out the new lines but then the comment is not really useful.
AccuRev commands that take a -c option for a comment must currently be enclosed in quotes and have no line breaks.
As for the output from git log 1234..4311 that could be captured as a manifest file and kept with the other files.
Dave
I'm not sure about doing it directly from the command-line without any extra step, and I'm hesitant to try anything on my client's AccuRev setup. That said, according to the entry on accurev keep from the CLI manual:
–c <comment>
Specify a comment for the transaction. The next command-line argument should be
a quoted string. Alternatively, the next argument can be in the form
#<comment-file>, which uses the contents of text-file <comment-file> as the
comment.
Default: enter a comment interactively, using the text editor named in
environment variable EDITOR (or a system-dependent default editor).
Reading this, I see two ways you can do what you want from the command line (meaning, not using the GUI).
1.) Pipe or cat your stat info into file, the use the #file syntax to get it into your commit
2.) Get your stat into into your clipboard, then don't give an argument to the keep command, let your editor open up, paste, save, and close.
There may be a way to get this all done via CLI without these middle-steps (perhaps you need to format the \x0a into \r\n or something?), but as I said, I'm unwilling to try it on my AccuRev setup as AccuRev gives me (and everyone else) enough trouble as it is.
HTH

How to run a vim script interactively from vim command line?

Is there a way to run these scripts from the : commandline with a few keystrokes?
Over the last couple of months, I've built a series of files full of vim-commands to auto-generate boilerplate code for my projects. It's allowed me to work faster.
However, the only way I know how to run these scripts is by assigning them to key-combinations in ~/.vimrc. There's only so many keys I can remap.
Is there a way to run these scripts from the : commandline with a few keystrokes?
For example, I have a unit_test_cpp.vim script, which builds a boilerplate unit test cpp file. I'd like to be able to type
:utc
or some other simple combination of letters with a simple mnemonic to run this script on my currently open file.
Open Vim and enter the following:
:source /path/to/vim/file/name.vim
If you are currently editing that file, you can also type:
:w <ENTER>
:source % <ENTER>
The percent sign (%) means the path to the currently opened file.
You could use the command feature of vim. In your unit_test_cpp.vim file you would add something like this:
command Utc call CreateUnitTests()
Now when you type :Utc it will call your function. The only limitation is that your command must start with an uppercase letter.
Script or function? If it is a function, try
:call FunctionName()
:run file.vim
:run is like :source, but :run doesn't need the path. It searches the runtimepath.
A Linux runtimepath:
$HOME/.vim,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
$HOME/.vim/after