Lets say that you have either URL or a link on a webpage that is a text file. How would be the easiest way for the user to be able to open that file in a Vim?
Right click and save link as?
Use a specific file extension that defaults to Vim?
Command line command?
Depending on how your vim binary was built you can just give vim the url:
vim http://www.google.com/
Vim spawns curl and grabs the file, then opens it.
Assuming you want to just open a link in vim, how about this:
curl http://www.google.com | vim -
EDIT
to make this command easier you can always user your browser of choice's "Copy link address" option.
EDIT
Given #speshak's answer and my own, I would say the "easiest" way would be option 3, "a command line command".
Solution 1: use command
" gvimrc
for g:chrome_exe in [
\'C:\...\Google\Chrome\Application\chrome.exe',
\]
if !filereadable(g:chrome_exe)
continue
endif
command -nargs=+ URL :exe "silent !start ".g:chrome_exe." <args>"
break
endfor
Now when you type: :URL https://news.google.com/topstories?hl=en-US&gl=US&ceid=US:en
it will open google news
Solution 2: use function
or if you have a file that records a lot of URLs, and you want to use hotkey to open it, then you can try in this way
" .gvimrc
let g:chrome_exe = 'C:/.../Google/Chrome/Application/chrome.exe'
function OpenURL()
normal "*yy
" let result = getreg("x")
" return result
:execute "silent !start ".g:chrome_exe2." ".getreg("*")
endfunction
map ,url :call OpenURL()<CR>
and then, you can open it with ,url
" test.txt
https://www.google.com/
https://news.google.com/topstories?hl=en-US&gl=US&ceid=US:en
Explanation of command
URL is a name, choose by you. (remember User-defined commands must start with an uppercase letter)
what is the command
command -nargs=+ Say :echo "<args>"
Now when you type :Say Hello World
Vim echoes "Hello World".
nargs
-nargs=0 No arguments
-nargs=1 One argument
-nargs=* Any number of arguments
-nargs=? Zero or one argument
-nargs=+ One or more arguments
I have used links before since RedHat days. The command would be
links http://www.google.com
If links is not installed, you can do sudo apt-get install links on Ubuntu 14.04 LTS to install it.
Hope it helps.
Related
HTTPie accepts paths as arguments with options that include the # sign. Unfortunately, they don't seem to work with shell completions in fish. Instead, the option is treated as an opaque string.
To stick with the file upload example from the HTTPie documentation with a file at ~/files/data.xml, I would expect to be able to tab complete the file name when typing:
http -f POST pie.dev/post name='John Smith' cv#~/files/da<TAB>
However, no completion is offered.
I have installed the completions for fish from the HTTPie project and they work for short and long arguments. This file does not specify how to complete the # arguments though.
In addition, I looked into specifying my own completions but I am not able to find a way of getting to work file completions with the arbitrary prefix.
How could I implement a completion for these path arguments for HTTPie?
Currently, the fish completions for HTTPie do not have completion for file path arguments with #. There is a more general GitHub Issue open about this.
If this is something you'd like to work on, either for yourself or for the project, you might be able draw some inspiration for the fish implementation from an HTTPie plugin for zsh+ohmyzsh that achieves your desired behaviour.
I managed to get the tab completion of the path arguments working with some caveats.
This adds the completion:
complete -c http --condition "__is_httpie_path_argument" -a "(__complete_httpie_path_argument (commandline -t))"
With the following functions:
function __is_httpie_path_argument
set -l arg (commandline -t)
__match_httpie_path_argument --quiet -- $arg
end
function __match_httpie_path_argument
string match --entire --regex '^([^#:=]*)(#|=#|:=#)(.*)$' $argv
end
function __complete_httpie_path_argument
__complete_httpie_path_argument_helper (__match_httpie_path_argument -- $argv[1])
end
function __complete_httpie_path_argument_helper
set -l arg $argv[1]
set -l field $argv[2]
set -l operator $argv[3]
set -l path $argv[4]
string collect $field$operator(__fish_complete_path $path)
end
The caveat is that this does not expand any variables nor the tilde ~. It essentially only works for plain paths — relative or absolute.
I'm trying to make a silent installation through a Windows Batch script with a file parameter, but I'm not being able to do it.
I have a file (params.txt) which contains the parameters that should be input during the installation (such as path, choices etc).
Obs.: It may also be by PowerShell.
I have something similar in Linux, which is pretty easy:
.../installer.sh < .../params.txt
But I'm trying in many different ways, with NSIS, MSI. But none of them seens to solve my problem with these parameters.
The closest that I've got was
C:\installer.exe /S
indeed its make the installation with the default parameters, but I would like to specify them through my file.
I've made many researches, even here in stackoverflow, but nothing that solves my problem.
Content of my params.txt file:
yes
no
C:\Software\MySoftware
yes
no
no
no
The installation prompts a few questions, and the file contains the answers that I need to give during the installation.
Also, the installer was generated using NSIS (Nullsoft Scriptable Install System) .
Thank you in advance.
NSIS supports the /S and /D=c:\installpath parameters by default, support for anything else has to be provided by the install author.
Install authors can check for specific parameters and/or a answer file:
!include FileFunc.nsh
!include LogicLib.nsh
Section
; Command-line parameter:
${GetParameters} $0
ClearErrors
${GetOptions} $0 "/Something" $1
${IfNot} ${Errors}
; Do Something
${Else}
; Do something else?
${EndIf}
; Answer .INI file:
Var /Global AnswerFile
StrCpy $AnswerFile $ExePath -4
StrCpy $AnswerFile "$AnswerFile.ini"
ReadIniStr $0 $AnswerFile "Options" "OtherPath"
${If} $0 != ""
File "/oname=$0\file.ext" "c:\mysource\fileForOtherPath.ext"
${EndIf}
SectionEnd
I installed the atom-runner package. I want to create a custom command to execute from the palette to save the current file and then execute the runner. Getting the editor and saving the file works.
runner:run fails as does AtomRunner.run()
atom.workspaceView.command 'MyEntry:runner', ->
editor = atom.workspace.getActiveEditor()
editor.save()
runner:run
To call a Command Palette command from code, you can use atom.workspaceView.trigger and give it the name of the command as a string. For example:
atom.workspaceView.command 'custom:runner', ->
editor = atom.workspace.getActiveEditor()
editor.save()
atom.workspaceView.trigger 'runner:run'
I changed the name of your custom command to custom:runner to fit in with the conventions of command naming in Atom and the conventions we've been using in the Atom community for simple commands in one's init.coffee. If you wanted to retain the use of "my entry" as the package name (or anything else that has two words in it), I'd recommend formatting it as my-entry:runner.
I found that with version 1.9.x the last line of the accepted answer did not work:
atom.workspaceView.trigger 'runner:run'
After some searching, found that this did:
editorView = atom.views.getView(editor)
atom.commands.dispatch(editorView, 'runner:run')
The OS is Ubuntu. I want to create file.txt in /home/z/Desktop where the content of the file is some text here.
The first and usual way is run nano /home/z/Desktop/file.txt and type some text here. after that, press ctrl+x, pressy followed by Enter.
The second way is run cat > /home/z/Desktop/file.txt, type some text here and press Enter followed by ctrl+c
I hope I can run single line of command to make it faster. I thought xdotool will work with the cat (the second way), but no, it not works
You can use "echo" in bash. e.g.:
echo "some text here" > file.txt
If you don't want a new line character at the end of the file, use the -n argument:
echo -n "some text here" > file.txt
How can I search the command history in cygwin?
I don't want to keep pressing the arrow keys to execute a command from console command history.
If you are using the default editing mode, do ctrl+R to search back through your history.
If you have done set -o vi to use vi editing mode, then it is esc-/
The history command is the way to go. I use
h ()
{
history | cut -f 2- | sort -u | grep -P --color=auto -e "$*"
}
so that I can type something like h git.*MyProgram, h ^tar -c, h svn:ignore, etc to pull up a sorted list of past commands matching a regex.
You might also want to add the following lines to ~/.inputrc:
# Ctrl+Up/Down for searching command history
"\e[1;5A": history-search-backward
"\e[1;5B": history-search-forward
With these in place, you can type a partial command prefix (such as gi or sql) then use Ctrl+Up to scroll back through the list of just your command history entries that match that prefix (such as git clone https://code.google.com/p/double-conversion/ and sqlite3 .svn/wc.db .tables). This can be a lot faster than searching and then cutting and pasting if you want to edit or re-execute a command that was fairly recent.
I use the history command in combination with grep, e.g. history | grep vi shows all commands where vi was used.
Checkout the "Gnu Bash Manual" (man bash) for the command "fc". E.g.fc -l -80 would list the last 80 commands, while other options let you search with RegEx...
Do
vi ~/.inputrc
Add
For arrow up/down bindings:
"\e[A": history-search-backward
"\e[B": history-search-forward
Or for page up/down bindings:
"\e[5~": history-search-backward
"\e[6~": history-search-forward
Close and open cygwin.
Voila.
I think one of the easiest way is to pipeline it with less and press search character ("/") and then type the command you wanna find.
history | less
and then
/text to find
to find the desired command
Another way
is to append the stdout form history command to a file: history > /cygdrive/path/file.txt
and then search in the document.