Okay description of problem, I have some files I often edit and navigating to them in ie: Thunar was getting to be a real PITA, now I could've symlinked to them in any convenient location(s) and still might but what happened to pop into my head was why not use a bash alias for it, so this is the result.
Couple of prelims, you can add bash aliases to your .bashrc file kept in your users /home directory in the appropriate section of the file, however if you don't already have one let's create a dedicated file to store bash aliases (if you don't already have such a file), create a normal text file in your /home, name it .bash_aliases ... There is nothing special needed here, the syntax goes as follows, add as many aliases as you like and I encourage comments to tell yourself what the alias is/does too, here's a snippet from mine to demonstrate.
- Code: Select all
# Check the systems current clock, top is cpu0, bottom cpu1
alias freq="cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq && cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq"
# Quick way to edit a file I use often.
alias tweak="/bin/bash ~/.bin/edit2.sh"
# Running a script from ~/.bin to edit a file.
alias patch='/bin/bash ~/.bin/edit.sh'
# This one is to open thunar in a directory I use often.
alias quick="/usr/bin/thunar /mnt/data/.directoryname/.blahblah/newstufftosave &exit"
That's all there is to it, the lines starting with # Are comments, bash doesn't care about them, they're there to let me know what and why I added that alias, otherwise the line beginning with alias is what's significant.
# Comment tell yourself what the alias is for or etc.
alias youralias="what-you-want-bash-to-do-when-you-type-that-alias-in-terminal"
Enclosed in "quotes" ...
Some of those are the ones I'm wanting to demonstrate here, such as alias patch="/bin/bash ~/.bin/edit.sh"
Notes: When I type the word patch into a terminal, what it does, the bash shell (which is the default user shell in a massive number of gnu/Nix distro's, including Debian(+based)then runs the designated script this ~/ is a shortcut for and just the same as typing out /home/yourusername ... In my case I have a directory named .bin in my users home, it's a .(dot) directory and that just means when you create a directory you name it with a .(dot) in front of it ie: .mydotdirectory, I like to use .directories because they aren't visible unless you unhide them, thus they don't clutter up the /home directory.
Anyway getting back to it, in that .bin directory I created a script, just a regular txt file. (end it with) the .sh extension, for shell. Here's the contents of the edit.sh file ...
- Code: Select all
#!/bin/bash
/usr/bin/leafpad /mnt/data/.directoryname/.blahblah/newstufftosave/patches &exit
Begin the file with the proper shebang #!/bin/bash for a bash script, though for any script start the thing correctly. What the rest of it does, /usr/bin/leafpad is the path to the leafpad text editor binary, I could've gotten away with just leafpad or gedit or geany of whatever but whatever, what follows that is the path to the file I want to open and edit in leafpad and the &exit(probably not necessary) but that tells bash to close. So to this point, when I type "patch" in a terminal, it runs the script in ~/.bin/edit.sh, which launches leafpad and tells it which file to open and that's what it does for me. One last VERY important part of dealing with shell scripts, make them executable with "chmod +x /path/to/scriptname.sh" in my case "chmod +x ~/.bin/edit.sh" Though you can do this in a graphical file manager, can open a terminal here in tha same location as the script etc. Also note DO NOT use sudo when dealing with files or scripts-etc in your users /home, your user already owns those and mucking around in your /home files with elevated priv's like as root/sudo can cause problems, easily solved but still ... standard warning.
When I run that alias "patch" the file I want to open, opens in the selected editor and then returns the cmd prompt to my terminal/shell for me. So it's ready to take further input. The edit2.sh is also a script which does the same for another file I often end up opening/editing.
Next up this one ... Same deal, there's a directory I often end up navigating to in my file manager and click, click, clicking the way into it gets tedious quick(even named the alias quick for it.) So this opens the directory I want in my selected file manager.
- Code: Select all
# This one is to open thunar in a directory I use often.
alias quick="/usr/bin/thunar /mnt/data/.directoryname/.blahblah/newstufftosave &exit"
Again surely could've just used simply "thunar" instead of path to the binary but again ... whatever. I could've created another script to do the same with thunar as was done with leafpad and the file I want to open/edit and it's easily enough done if you wanted but all this one does is launch thunar and opens it in the directory I want it to open in, that could be anywhere ie: /usr/share or / < (for opening it in the root directory.) and the &exit closes the terminal/shell. These puppies can also of course be used in keybinds(keyboard shortcuts), menu entries, icons, panel launchers or whatever else too. Any and/or every desktop or window manager should have easy means of setting up such things and the cmds you'd use are the same-similar. You should get the general idea ...
Other bash alias related stuff:
Just edit that .bash_aliases file whenever you want to add a new alias, note that they won't take effect in a given terminal, until you close + re-open the thing, so the new aliases are recognized(the .bash_aliases file gets sourced again.) Also at times it's easy to forget what aliases a person has set, to see a list of the puppies just type "alias" in a terminal and it'll list them out, though without the comments, to see those use "cat .bash_aliases" to get the full contents of the file, including comments OR setup an alias to check the contents of "cat .bash_aliases".
