I make bash/ruby commands for basically everything in my development workflow (todo, pullrequest, asciiart, remind and so on). People I work with always ask me to share my commands with them, but to do this, I transfer the files to their computer, then xargs through each file with chmod +x and mv /usr/local/bin.
Wondering what work I can do upfront to make the import process easier. Fine with some Mac installer tool, or a git & makefile solution, but I'd really like to get the process down to a single click or command if possible.
Use Nix expressions with Nix package manager: https://en.m.wikipedia.org/wiki/Nix_package_manager ! It is supported on Macs.
It is possible to make a Terminal command executable by just selecting it in Finder and pressing the keyboard shortcut.
Below is the method for solving your problem.
1. Create a macOS service using Automator
1.1 Open Automator and create a new service
1.2 At the top, choose Service receives selected no input in Finder
1.3 Drag Get Selected Finder Items action to the workflow
1.4 Drag Run Shell Script action to the workflow
1.5 In Run Shell Script action, select Pass input: as arguments and in the text field, type:
chmod u+x "$#" && mv "$#" /usr/local/bin
1.6 Save service
2. Distribute service to colleagues’ computers
2.1 The created service is located in ~/Library/Services
2.2 Move it to other computers and install it by opening the file, or manually copying the service to ~/Library/Services
3. Bind service to a keyboard shortcut
3.1 Open System Preferences → Keyboard → Shortcuts → Services → General
3.2 Choose an appropriate keyboard shortcut for your service
You can also run the service by right-clicking on file and selecting the action in Services submenu at the bottom of contextual menu.
Share a Dropbox directory with them that contains your scripts, and ensure that it is in their PATH.
No updates are necessary when you improve your scripts as they will automatically see the latest version.
Manage the directory with git for version control.
Thought I'd post the standard makefile solution for completion sake. Works for macOS/ and GNU(Linux)
Put a makefile in the project directory.
So the directory looks like [ my-executable makefile readme.md ] or whatever
# makefile
install:
# side note: `#` prevents make from printing the command itself
#echo "installing..."
#chmod +x my-executable
#cp my-executable /usr/local/bin
#echo "done!"
then inform recipients to download/clone and run sudo make install from the project directory
Or for a one-line solution (presuming the recipients trust you a little too much)
git clone https://githost.com/myaccount/myrepo.git &&
sudo make install -C myrepo &&
rm -rf myrepo
(download, install, remove cloned directory) – user 16 mins ago
Related
I use WSL almost exclusively, and only switch to main windows for browsing and running Windows native programs. I have a git repository located at /mnt/c/myrepo. In order to "install" the code inside /mnt/c/myrepo I need to move it to /mnt/c/otherlocation/renamed. Instead of executing cp -r /mnt/c/myrepo /mnt/c/otherlocation/renamed every time I do a git pull from /mnt/c/myrepo, I would like to symlink /mnt/c/myrepo to /mnt/c/otherlocation/renamed. However when I do this, the program which consumes /mnt/c/otherlocation/renamed isn't able to view the "contents" of renamed as a directory.
I have been all over the WSL github repo and issue tracker trying to find a solution to this issue. I see a lot of exclamations about how symlinks "just work". I have enabled every Windows 10 developer feature I can find, I even followed some reddit thread where someone claimed that purchasing Pengwin and creating a symlink from Pengwin would ensure this compatibility, but I still can't seem to make this work.
The basic usage I need, is allow me to view "renamed" as a directory from windows, or for windows to recognize the symlink as a symlinked directory.
from wsl:
ln -s /mnt/c/myrepo /mnt/c/otherlocation/renamed
from windows:
open file explorer
navigate to c:\otherlocation
open mydir and view the contents as if it were a native directory
How do I do this?
Do the symlink in Windows, in cmd.exe:
mklink /d C:\otherlocation\renamed C:\myrepo
It doesn't make sense creating the symlinks in WSL if both directories are in Windows.
This symlink will work in WSL as well.
The solution to this problem is simply to use the relative path when declaring the link. If you want to link from windows to windows, you should relatively path from the current directory and then you can link anywhere you wish.
From the example, instead of this:
ln -s /mnt/c/myrepo /mnt/c/otherlocation/renamed
Do this:
cd /mnt/c/otherlocation
ln -s ../../myrepo ./renamed
I am new to computers and using the terminal. Most tutorials I look at for downloading tell me to go to usr/local/src. However, I don't find this on mac. Should I just make a directory called src?
Or is this something specific only to linux users?
If someone could tell me how much difference it makes for this directory to exist or not that would be great. Can I complete my installations in usr/local itself?
Thanks
Using the Finder, you can press Cmd-Shift-G and type /usr to display that folder. The /local folder is there by default, but not its /src subfolder. The Finder, of course, can easily create it for you.
As #cricket_007 mentioned, you need to be certain of what you're doing in this area of the system — that's why OS X doesn't display those folders by default. If you understand the risk and want to see everything in the Finder, you can issue the following Terminal command:
defaults write com.apple.finder AppleShowAllFiles YES
... then type:
killall Finder
and it will look like this. The hidden folders have a slightly faded appearance, but you can navigate into them as desired:
Alternatively (for High Sierra and above)
You may simply use the key combination: " Cmd Shift > " to toggle on and off hidden file display.
It depends what you are doing. If you're messing about just create one in your home directory:
$ cd ~
$ mkdir src
If you building stuff via configure etc., and you want to install it into /usr/local (the default install prefix), then just do this:
$ cd ~/src/packagename
$ ./configure ... options ...
$ make
$ sudo make install
In the "Run Script" build phase of my project, everything works if I type in the script into the text box for "run script" in build phases.
But to make editing / diffing etc easier, I thought I would save the script as a file as part of my project, and just fill in the path in the text box instead:
Eg: I paste the following path in the text box.
/Users/superman/Documents/Projects/SomeProject/scriptname.sh
But when I try to build this, I get a "Permission Denied" message.
What can I do to fix this? If I cut/paste the actual code, then it just "works". My user account is an administrator account. No one else uses my machine.
You can simplify your Xcode project file a little further and not require the "bin/sh " in front of the script name.
To avoid this, you need to turn on "execute" permissions for users (Xcode in this case) of the file.
Steps
Go into terminal
Navigate to where your script is
run chmod 755 yourScriptName.sh
Put /bin/sh in front of the path to the script name.
/bin/sh /Users/superman/Documents/Projects/SomeProject/scriptname.sh
Just use
chmod u+x nameofscript.sh
Thats it .
Simple Steps:
Go to the <your_Script>.sh via cd <Your_Path_To_.sh_File>
Run chmod +x <your_file>.sh
Thats it
I'm using git portable on windows. It's rather user friendly, but there is one thing that bothers me. Every time I run it I have to type the entire path to the project directory, which is quite long sometimes. Maybe it's not a serious problem, but it would be very nice to shorten it. I tried the following:
bash script.sh // cd in this file // nothing happens
create symbolic link it - it just copies the directory
create windows shortcut - can't open it within git console
Anybody managed to solve this?
You can right click on the Windows shortcut that launches Git Bash, edit its properties and modify the "Start in" path to your project path. Every time you launch this shortcut, it will cd into that project path.
Or you can add an alias to your ~/.bashrc like below:
alias proj="cd /path/to/project/"
This will allow you to cd into the project dir on demand by typing the alias name at the prompt.
If you run git-bash.bat from Portable git, it should work mostly as normal git installation. So, to work with a specific repository, just cd into it:
cd /c/code/MyRepo/
git whatever
I've added
cd /c/dev
to
~/.bashrc
with
echo cd /c/dev >> ~/.bashrc
But I'm running MSysGit the non-portable version. Hope this helps in some way anyway.
Looking for a solution to quickly navigate to long paths in a shell (particularly Max OS X Terminal.app).
Say my path is ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently
Instead of cd ~/This/Is/A/....
I would like to be able to store favorites/bookmark directories so I could do "cd myPath"
Are there any binaries or tools available to do something like this?
I've found the packages 'Apparix' and 'Goto' which together make the stuff dreams are made of for us terminal junkies.
Naturally, I had trouble installing Apparix, but I figured it out in the end.
How To Install Apparix on Mac OS X:
Download the tarball from Apparix's homepage.
Unpack the tarball, cd to the unpacked folder.
Run this command ./configure --prefix=$HOME/local && make && make install.
Run man apparix, scroll down to the heading BASH-style functions, copy everything within that section (delimited with ---) and paste it into ~/.bash_profile.
That's it. You should now have Apparix up and running on OS X (further install info and usage is on Apparix's homepage).
Another solution is to use Bashmarks, which allows you to this
$ cd ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently
$ s shortname # save current path as `shortname`
$ cd /
$ g shortname # cd to ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently
You can use aliases (stick them in your ~/.bash_profile if you want them to always load)
alias cd_bmark1='cd ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently'
Then use by just typing
cd_bmark1
into the console
I know you already found an answer that worked for you, but a couple of more lightweight suggestions that might help others looking for similar things
If your directories are relatively fixed, just long and far away from each other, you can use the CDPATH environment variable to add directories to the search path when typing the "cd" command. If the directory name you try to cd to isn't in the current directory, the other entries in your CD path will also be looked at (and it's also tab complete aware, at least in bash and zsh).
Switching to zsh rather than bash and using the excellent directory stacks abilities. With it, you can maintain a history of directories that you've visited, view the history with the "dh" alias, and easily switch to a directory by using quick shortcuts (ex: cd -3 to switch to the 3rd directory in your history stack).
Why not having a symlink ?
ln -s ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently bmark
cd bmark
I use to.sh daily to create and navigate bookmarked paths in bash. It supports tag autocompletion and the ability to easily add/remove bookmarks.
https://github.com/Grafluxe/to.sh
Full disclosure, I wrote this tool :)