Where is the default zsh history file? - default

HISTFILE isn't set in my .zshrc file.
To which file is zsh history saved by default?
Or, is the history just being stored in memory?

Zsh has no built-in default value for HISTFILE. The zsh distribution
comes with a setup wizard for new users which has the value
~/.zsh_history built in...
More by Gilles on Command history in Zsh - Unix SE

Related

How to avoid printing of arrow keys while taking input from terminal in C? [duplicate]

I find that the arrow keys don't work on the sqlplus console.
For example if I press left arrow key, it shows like
SQL>^[[B
Does any solutions exist to solve this problem?
You can use a third party utility called rlwrap.
rlwrap is a readline wrapper, a small utility that uses the GNU
readline library to allow the editing of keyboard input for any other
command. It maintains a separate input history for each command, and
can TAB-expand words using all previously seen words and/or a
user-specified file.
So you will be able to use arrows and also get a command history as a bonus.
After you have installed the utility run sqlplus the following way:
$ rlwrap sqlplus
As Johnny suggested, you can install the rlwrap utility to manage command history for any other command, including sqlplus. Another useful trick is to alias the wrapped version of sqlplus so you don't have to type rlwrap sqlplus every time.
alias sqlplus="rlwrap sqlplus"

How to make my Linux C program accessible from bash

Say I made and compiled a small program in C to count the bytes of a file, called filebyte. To run it I would use ./filebyte
Now I want to make it universal on bash, like for example to run a php file, I would use bash command php file.php, same way I would like to run my program, filebyte filename.
How do I do this?
Thanks!
I often create a bin/ directory in my home directory, for small custom applications.
You then need to add that directory to your PATH, which is a list of colon-separated paths that your shell searches for executables when you type a name on thr command line.
This is usually accomplished by putting this in your ~/.bashrc file:
PATH="$PATH:~/bin"
Check the environment variable PATH and put the executable in one of the directories listed. You can also put it in a custom directory and then append it to PATH. You can check it by executing printenv PATH
If you want it for your current active shell alone, do
export PATH=$PATH:</path/to/file>
For permanently making the file available add the above line to ~/.bashrc
Why add it in PATH variable, man bash says why,
PATH The search path for commands. It is a colon-separated list of
directories in which the shell looks for commands (see COMMAND
EXECUTION below). A zero-length (null) directory name in the
value of PATH indicates the current directory. A null directory
name may appear as two adjacent colons, or as an initial or
trailing colon. The default path is system-dependent, and is set
by the administrator who installs bash. A common value is
''/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin''.

How to set default opener [duplicate]

How can I set TextMate as default text editor on Mac OS X?
I've tried it with
ln -s /Applications/TextMate.app/Contents/Resources/mate ~/bin/mate
export EDITOR='mate -w'
but that doesn't work.
Just right (or control) click a file of the type you want to change and:
"Get Info" -> "Open with:" -> (Select TextMate) -> "Change All"
The method through Finder is not practical. If you're a developer, your files likely include .profile, .gitconfig, .bashrc, .bash_profile, .htdocs, etc.
The best way to do this is in Bash (for Sublime Text 3):
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}'
For other text editors, I assume you can replace 'com.sublimetext.3' with the proper string. You could probably Google for your text editor's name + "LSHandlerContentType=public.plain-text" to figure out what your app's string would be.
For me, this changed the defaults for both Finder, and
$ open ~/.bashrc
Have you modified your shell PATH environment variable to include ~/bin? That directory is usually not included in PATH by default on OS X. It might be simpler to create the symlink in /usr/local/bin which is usually included in PATH. Try:
echo $PATH
This worked for me on OS X v10.11 (El Capitan):
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.macromates.textmate.preview;}'
For TextMate 2:
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.macromates.TextMate;}'
And you need to restart after that.
To change the default text editor across the board, use the aforementioned method (i.e., "Get Info" → "Open with:" → (editor of choice) → "Change All") on .txt files. Then it will be used as the default editor for any text-based file that doesn't yet have an application preference for its extension.
For instance, if you use the terminal, the command open -t will use your preferred text editor, which is whatever application is associated with .txt files. By default this is (you guessed it) TextEdit, unless you explicitly specify otherwise.
I found Replace Text Edit as the default text editor on apple.stackexchange which works really well.
For developer-type files like .gitignore, use the last option provided:
duti -s com.macromates.TextMate public.data all
Substitute your editor's CFBundleIdentifier as needed. To find it, locate the application file, right-click and choose Show Package Contents, then open Info.plist in the Contents folder. CFBundleIdentifier should be near the top...
This work on Catalina. I'll update my answer if/when I update my OS.

How to set Home and Path directories in C?

I am programming a small unix shell written in c. I want it to do only some basic commands for now. e.g. ls, pwd, ch
My problem is how do I set the Home directory and Path directory? I want to read the configuration from a text file so it can be easily changed whenever.
I am going to be using execv() to call unix functions such as ls. For example PATH
should determine the directories my shell should use to search for executable programs
when the user types a command
Thanks
They are all simply environment variables that you manipulate e. g. through setenv(3) (run man 3 setenv for details). The variables are HOME and PATH. See also man 7 environ.
Note that setting/changing an environment variable only influences the current process and all processes forked from it after the setting/changing (unlike in Windows, AFAIK).
Check out the function setenv. See man 3 setenv for information about it.
Unix already offers you an environmental variable that contains all the paths where system executables are stored. Retrieve the variable in your code with getenv("PATH"); Each path is separated with a ':' so all you need to do is tokenize and begin searching those paths for the executable your command wants to run. In this function you should also be able to search any path of your choosing for an executable.
You can decide what directory you want to start in ("home directory" as you say) by manipulating the current working directory before the shell prompts with chdir(). You can also use that unix function for implementing a cd command that can be used throughout the run time of the shell.

How to save "history" automatically depending on the directory

I work extensively using the shell. When I continue working on some project one week later, I go to some "folder" and realize that I do not remember what I was doing. Sometimes and before stopping work what I do is:
history > DIRX_HISTORY_20100922
so later I have a look at the commands I used, I can remember much better what I was doing.
I wonder if somehow, some script or something could do this automatically each time I type a command in a directory, so this DIRX_HISTORY_20100922 is created and a new one is modified depending on the date and on the directory name.
Thanks
Have a look at my history logging functions. They save the current directory along with the command that was executed. You can grep for the directory and it will show you the commands that you were using there.
Bash's PROMPT_COMMAND variable can be used to save the last line of your history to a file for every command you enter.
ie.
PROMPT_COMMAND="history 1 >> DIRX_HISTORY"

Resources