Can I open a file with geany from the terminal - terminal

I know there is a shortcut to open a file with sublime text from the terminal but id there something similar with geany, the only info I can find online about it is opening a file from geany to the terminal.

If Geany is inside your path, just call geany <file>. This should work on every platform, Geany is running.
Out of Geany's man page:
SYNOPSIS
geany [option] [+number] [files ...]
This will open files either in a new session or, if already a session of Geany is running, inside the existing one.
A file can be given as space separated list and might take even line numbers:
files ...
A space-separated list of filenames. Absolute and relative
filenames can be used. Geany also recognises line and column
information when appended to the filename with colons, e.g.
"geany foo.bar:10:5" will open the file foo.bar and place the
cursor in line 10 at column 5.

You can use open:
open [PATH_TO_FILE] -a [PATH_TO_GEANY_APP]
The a option defines which application to use.
To make this shorter, create an alias:
Something like echo 'alias geany="open $1 -a [PATH_TO_GEANY_APP]"' >> ~/.bash_profile && chmod u+x ~/.bash_profile. Then open a new Terminal window and type geany [path_to_file].

Related

bash - supplying variable as a file path

I'm trying to specify a variable for opening up a file with a particular app, but no matter how I attempt to reference it, it's not working.
sublime1=/Applications/Sublime\ Text.app/
sublime2="/Applications/Sublime\ Text.app/"
sublime3="/Applications/Sublime Text.app/"
I've been trying different ways of setting the variable, but for each of the variations I've tried, it fails.
open ~/.zshrc -a $sublime1
open ~/.zshrc -a $sublime2
open ~/.zshrc -a $sublime3
The file /Users/matthew/Text.app does not exist
It gives me the same error for each, so I assume they're equivalent. Even when I try cd $sublime it also fails, but slightly differently...
bash: cd: /Applications/Sublime: No such file or directory
Update:
It was suggested by Charles to use a function to accomplish the task of quickly opening something in sublime.
sublime() { open "$#" -a "/Applications/Sublime Text.app/"; }
Will allow you to simply run
sublime ~/.zshrc
These assignments are correct:
sublime1=/Applications/Sublime\ Text.app/
sublime3="/Applications/Sublime Text.app/"
The problem is with the invocation. Variables used as command line arguments are subject to word splitting and globbing. You need to double-quote them, like this:
open ~/.zshrc -a "$sublime1"
open ~/.zshrc -a "$sublime3"
try using sublime1=$(/Applications/Sublime/Text.app)
and using chmod 770 Text.app on Text.app in the command line
sorry for my english...

Delete specific line from Zsh history

I'd like to remove a specific entry in my Zsh history.
Zsh's fc and history don't have any options to delete entries. I've tried looking for the ~/.zhistory but that doesn't exist. How can I go about finding the location of the history file and remove the entry?
You are looking in wrong File. Look at ~/.zsh_history not ~/.zhistory To view in which file your history is saved:
echo $HISTFILE
And delete:
rm $HISTFILE
Clearing Zsh History (oh-my-zsh)
close, quit and re-open iTerm
run nano .zsh_history
use the arrow keys to navigate to the part of your history you'd like to delete.
use the delete key to remove all unwanted history logs.
Once you've removed everything you'd like to remove, select control X to Exit.
You'll be prompted to Save the changes. If you're happy with your changes click shift Y.
You'll be asked where you'd like to save your changes. Select control T to save to File.
navigate to your .zsh_profile with your arrow keys and press enter.
Quit and restart iTerm.
type history to confirm the deletions.
You've successfully cleared your Zsh history.
osxterminalzshoh-my-zsh
Clear zsh history on unix systems.
echo "" > ~/.zsh_history & exec $SHELL -l
open ~/.zshrc
add the following line
alias clear_history='echo "" > ~/.zsh_history & exec $SHELL -l'
Save and close the file
Close the console or type zsh
if you to see the result directly, but this will open another zsh shell in the old one
Now you can clear the console typing clear_history
All the previous answers are good, this is simply the solution that worked for me.
You can use these commands to open the ZSH command's history(When you are in the home or ~ directory) and assume that you know how to use vim or nano :
nano ~/.zsh_history
vim ~/.zsh_history
open ~/.zsh_history
then you can delete the lines you want manually and save the file.
and if your zsh_history list is too long, for convenience use this:
enable mouse move and line numbering in the Vim environment by adding this to .vimrc:
open .vimrc:
vim ~/.vimrc
add these to .vimrc and save it(press ESC, enter ":" , write wq, and press enter):
:set number
set mouse=a
use the mouse to scroll easily in zsh_history by using Vim.
if you want to enable copy in Vim use holding shift on the keyboard.
read this for more info
https://www.techrepublic.com/article/how-to-effectively-clear-your-bash-history/
TL;DR
cat /dev/null > ~/.zsh_history
Type and run at the zsh command line, openĀ ~/.zsh_history (This opens TextEdit on my Mac.)
Delete any lines in the file
Save and close the file
Close/Exit the Zsh completely and restart the Zsh (this step is important!)
Now, open zsh and the history command does not show the lines that you deleted
This function will remove any one line you want from your Zsh history, no questions asked:
# Accepts one history line number as argument.
# Alternatively, you can do `dc -1` to remove the last line.
dc () {
# Prevent the specified history line from being saved.
local HISTORY_IGNORE="${(b)$(fc -ln $1 $1)}"
# Write out history to file, excluding lines that match `$HISTORY_IGNORE`.
fc -W
# Dispose of the current history and read the new history from file.
fc -p $HISTFILE $HISTSIZE $SAVEHIST
# TA-DA!
print -r "Deleted '$HISTORY_IGNORE' from history."
}
If you additionally want to prevent all dc commands from being written to history, add the following in your ~/.zshrc file:
zshaddhistory() {
[[ $1 != 'dc '* ]]
}
Alternatively, for a comprehensive, out-of-the-box solution, use my Zsh Hist plugin.
E.g. with vim you can easily delete the last n lines like this:
Open file: vim ~/.zsh_history
Go to the bottom of the file: G
Mark lines: V -> move up with arrow key
Delete: d
Write & quit: :wq
Or you can just navigate with the cursor and delete any particular line with dd
Open .zsh_history with your favourite editor and save keystrokes.
e.g. subl .zsh_history will open up history in Sublime editor and then delete whatever you want.
You can use TextEdit or other editors also.
This worked for me:
LC_ALL=C sed -i '' '/line/d' $HISTFILE
Replace "line" with what you want deleted.
From this answer:
https://stackoverflow.com/posts/13661794/revisions
For ZSH
To locate the history file do :
echo $HISTFILE
Then simply edit the file and remove any lines you wish to be gone as you would with history -d id.
Save the file.
Open a new terminal and you should see that there is nothing to see anymore !
However I am amazed that history -d does not exists. If it does exists it's well hidden.

How can I create and open a file from terminal with a single command?

To create a file from terminal I type the following...
$ touch filename.py
To open the file I just created from terminal, I then type...
$ open filename.py
I'm curious to know if there is a terminal command that does both...create and then open (I'm super lazy).
in .bashrc
lazytouch()
{
touch $1
open $1
}
then type
$ lazytouch anything.really
This is as lazy as one can get:
$ echo "your text" > myfile.txt
Simplest way to do this is
touch filename; open filename
Example
touch myfile.py; open myfile.py
What I do when I want to create a file, edit it and just save it is I type vim at the terminal. vim is a text editor. If you just type in vim you would see the text editor.
But if you type for instance vim example.txt you open vim and from then on you are working in the file you created. The file does not get saved until you say so. So by pressing i you enter the edit mode of vim. Allowing you to put text in the file. If you want to save just enter escape followed by :w, meaning you are saving the file with the name you have it to it, so for this example it would be example.txt. After you saved it, everything you type after pressing Esc is shown left down in the screen, simple type :q to quite it.
If you realise you do not really want to save the file you can just type :q! and if you were currently in the editing mode, meaning you were typing something, you just press Esc once followed by :q!.
So short summary:
vim example.txt (opens the editor if saved it will use the given name)
s (will enable edit mode, you can write stuff)
Esc (when you want to stop editing)
:w (save the file)
:q (quit the file, only usable when saved!)
:q! (discard the save and just exit the file)
you can use the following to create a file named "filename.py", insert "Hello World" into the file and then open the file,
$ echo "Hello World" > filename.py && open filename.py
On a Mac to create a lazytouch function to create and open a file in one line you have to edit .bashrc. You might have to first create it. Beware if you are a novice programmer. Some of these commands might require you to prepend sudo for permission to create and save. Enter these commands in terminal.
$ cd ~
$ touch .bashrc
$ open .bash_profile
Enter this profile in .bash_profile to check for .bashrc
# To get aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
Remember to save .bash_profile. Then in bash do this.
$ open .bashrc
Enter this text in the .bashrc
# .bashrc
# User specific aliases and functions
lazytouch() {
touch $1
open $1
}
Remember to save .bashrc
Now you can cd to any folder then create and open a file with one line.
$ lazytouch anything.really
you can use:
cat -> youNewFile.someExtension
Example:
cat -> myNewFile.txt
After you are done press Ctrl + d to save or Ctrl + c to abort (but in this case it's gonna save an empty file.
The redirection operator ( > ) will create the file if it doesn't already exists in your folder and you will be able to edit it right a way through the terminal.

How do I open a file in Vim from inside a Conque shell

Often I find my self navigating the filesystem from a Conque shell in Vim and want to open a specific file inside my existing MacVim session. Is this possible ? - I was hoping for something like:
shell> open some/file.txt
and then have file.txt pop up inside my existing Vim window (preferably in a new tab).
Note: I am using #wycats vim dot files (not sure this matters).
Type from ConqueShell
mvim --remote-tab-silent filename
This will open the file in a new tab in MacVim
You could also write a Bash alias to shorten the command (assuming you are using bash).
Put in your ~/.profile
alias vim='mvim --remote-tab-silent'
this would enable you to type
vim filename
from ConqueShell or bash, and have it open in a new MacVim tab, rather than terminal vim. It of course does disable your ability to run standard vim (although you could still use the vi command), so maybe you would want to name the alias differently.
Just to add, this will work only if you placed the mvim executable on your path E.G. /usr/bin/mvim. It comes with the MacVim.app
Often I find my self navigating the filesystem from a Conque shell
The beauty of running a shell from inside vim is you have all of vim and the shell at your disposal.
gf is your friend. Once you get the file you want displayed on the screen in some way, you can enter normal mode, move the cursor to the file you want to edit, then use the gf command to navigate to the file. There are many ways to use this. Any program or command that outputs file names is great for this (ll, git status, etc). You could also type the filename into the shell, just to make it visible on the screen without actually running any terminal commands (tab completion is handy here).
It is possible, you can start vim as server and then add as many files as you want, but I'm not very familiar with this, so I can't give you just a direction.

Open files in existing Gvim in multiple (new) tabs

I have put some aliases in my .bashrc to open a group of project files in gvim, each in their own tab:
gvim -p <list of file names using absolute paths>
This is all well and good, except there are several groups of files I might want to move between at any given time (my current project uses Ruby on Rails, so that explains that). What would be really awesome is if I could append the new tabs to an existing instance of gvim. In my last position I worked on Vista; I got around this by opening a bunch of empty tabs in gvim, which allowed me to right-click on a filename and choose "Open in existing No-Name gvim." Now I use Ubuntu and there's no such thing on the context menu. Is there any way to do this from the command line?
If vim is compiled with the clientserver option, you can do it. Start your vim instance with the following flag:
$ gvim --servername GVIM # GVIM is the server name. It can be anything.
To open more tabs in this instance, you can run the command:
$ gvim --servername GVIM --remote-tab file1 file2 file3 ...
The clientserver feature in vim is very handy. It's not limited to opening files; it can be used to send any command to vim using the command-line. For example, to close a vim instance remotely, you can use:
$ gvim --servername GVIM --remote-send '<Esc>:wqa<CR>'
From inside of Gvim, type :tabe {file_name}. This opens the named file in a new tab. If you aren't fond of typing long filenames, try this:
:tabnew
:e .
This will open a new, blank tab page and open a file browser. You can mouse click your way around or use the keyboard. Click or hit the enter key on the file you want to open it. Try using the keyboard to position the cursor over the file you want to open and then hit 't'. This opens the selected file in a new tab, keeping the file browser open in the first tab. This might be a fast way to open a bunch of files.
There are a whole lot of things you can do with tab pages that might make life easier. To get to the relevant section in Vim's on line help manual, type :h tabpage.
Want your Windows context menu to allow you to open files in a new tab of the currently open gvim window?
Save this as as a file called temp.reg and double-click it to add the settings to your registry. Be sure to modify the path to vim if yours is different.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim]
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim\command]
#="\"C:\\Program Files (x86)\\Vim\\vim73\\gvim.exe\" -p --remote-tab-silent \"%1\" \"%*\""
You will now have a context menu like this:
Linux users may use this kind of script:
#!/bin/bash
ANS=`pgrep -fx "gvim --servername GVIM"`
echo $#
if [[ ! $ANS ]]; then
gvim --servername GVIM
fi
if [[ $1 ]]; then
gvim --servername GVIM --remote-tab "${#}"
fi
And then edit gvim.desktop file for using this script:
Exec=/home/user/bin/my_gvim_script.sh %F
There is a way:
n*.cpp|tab ba
or if you like to split:
n*.cpp|sba
If you wish to know more:
:help ba
and I don't know what is n , but it would not work without it.
Here is my gvim start-up script. It is an extension of previous answers. It ensures only one gvim instance will run when gvim is called under all circumstances:
gvim is called without filename when no gvim instance is running; gvim is started.
gvim is called without filename in the presence of a gvim instance; an empty new tab is opened.
gvim is called with a filename with or without a gvim instance; a tab is opened showing the file.
This will mimic the standard behaviour of other editors.
#!/bin/bash
exec=/usr/bin/gvim #the path to gvim
if [ $# -eq 0 ]
then # no filename given
if [ -z $($exec --serverlist) ]
then # no filename given and no gvim instance
$exec -f --servername GVIM > /dev/null 2>&1
else # no filename given, but a gvim instance exists
$exec -f --servername GVIM --remote-send ':tabnew<CR>' > /dev/null 2>&1
fi
else # filenames given
$exec -f --servername GVIM --remote-tab "$#" > /dev/null 2>&1
fi

Resources