
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
gem install clone_git_file
This gem allows you to replace these commands:
mkdir -p ~/dev/author
cd ~/dev/author
git clone https://github.com/author/repo
cd repo
myeditor file.rb
with:
ogf https://github.com/author/repo/file.rb
(if you choose to setup an alias)
This gem will clone the repository containing a file, optionally opening that
file in your chosen editor. If the repository already exists in the specified
directory, any uncommitted changes will be lost (git reset HEAD --hard
will
be run). The repository will be pulled after resetting, to get the latest
changes.
The editor that will be used is specified using the EDITOR
environment
variable, which allows you to easily override your editor only for this command.
At a minimum, you need to specify a target directory and url:
TARGET_DIRECTORY=~/dev clone_git_file https://github.com/brandoncc/clone_git_file/blob/master/README.md
That will clone this repository to ~/dev/clone_git_file
, then switch to the
master
branch. A message will then be shown giving you that location.
There are command switches available as follows:
Switch | Description |
---|---|
-o, --open | Open the file in the specified editor after cloning |
-t, --terminal | Output the command which would be used to open the file in your editor, as text in the terminal. This is useful for piping into other commands. Since Ruby system method executions are run in a child process, this is useful for opening the file in your editor in the current shell (more details in the bonus section). This is equivalent to -ot . |
-s, --silent | Suppress messages from the cloning process. If you want to pipe the output of -t into a command, you should also use this. |
If you want to override your default editor, just add EDITOR=myeditor
to the
beginning. For example:
EDITOR=mvim TARGET_DIRECTORY=~/dev clone_git_file https://github.com/brandoncc/clone_git_file/blob/master/README.md
You can also supply the repo url or a repo subdirectory url, and that directory will be opened by your editor.
Setup an alias and/or function to make using the gem easy. For example, here are mine (zsh):
alias cgf="TARGET_DIRECTORY=~/dev EDITOR=mvim clone_git_file $1"
function ogf () {
echo "Cloning, your editor will open when clone has completed..."
source <(TARGET_DIRECTORY=~/dev EDITOR=mvim clone_git_file -ts $1)
}
cgf
clones, then prints a message with the location of the cloned
file/directory.
ogf
prints the commands to open the file/directory in my editor. I then
use source <(...)
to pipe the printed command to source
which runs it
in my current shell. This fixes some weird things that happen when opening
the editor in a child process, and also allows the current directory of my
current shell to be changed (instead of the child process shell which will
be lost when you close the editor).
ogf
has to be a function so that $1
will expand properly. If you use an
alias instead, $1
doesn't hold the correct value in the nested command.
-s, --silent
is only available on operating systems which can direct output to /dev/null
, which means it is unavailable on Windows.FAQs
Unknown package
We found that clone_git_file demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.