Sample Header Ad - 728x90

Sync terminal history in c shell

2 votes
1 answer
1425 views
For work, I remote into a linux server that uses c shell rather than bash using Remote Desktop. While in session (lets call it session 1) I'll open up many tabs in a given terminal and type commands throughout all of them. I'll also sometimes open up additional sessions (lets call them session 2 and session 3) with many tabs in their respective terminals and type many commands throughout all of them. I have noticed that the history command when invoked in any tab of any terminal across any session does not include all of the commands I have used across all of the tabs and sessions. only part of the commands are saved. I would like a history that: - Remembers *all* commands typed, regardless of what tab, terminal or session I am in - Instantly accessible from any of tabs/terminals/sessions While there is a great post from nearly 12 years ago that describes how to do exactly this, that is for a bash environment, not a c shell environment. As such, there is no .bashrc but rather a .cshrc. I'm looking for a solution that works in the c shell environment. UPDATE: I tried adding this to the top of the .cshrc file:
set history=10000
set savehist=(10000 merge)
alias precmd 'history -L, history -S'
Where set history=10000 sets the size of the history list, set savehist=(10000 merge) sets the number of lines in the history list to save to the .history upon exit of a session, and the merge merges the history of a session with the overall history upon exit, alias precmd 'history -L; history -S' sets some commands to run before every command at the terminal is ran. The -L option appends a history file to the current history list. The -S option writes the history list to a file. This didn't do what I wanted. Now every time I type history at the terminal, the size of the command history list jumps up in size _dramatically_. The command history list _isn't_ updated across terminal tabs in a session. I tried this too, with no improvement:
set history = 10000
set histdup = erase
set savehist = (${history} merge lock)

alias precmd 'history -S'
alias postcmd 'history -M'
I'm not entirely sure what all of the lines mean, but I know that precmd supposedly means before a command is ran, do this and postcmd supposedly means after a command is ran do this. The -M option merges the contents of the history file with the current history list and sorts the resulting list by the timestamp contained with each command. I feel like I am close, like I'm missing some key line to add in the .cshrc file, or maybe I need to change the order around.
Asked by Dan (21 rep)
Feb 1, 2022, 06:42 PM
Last activity: Jan 1, 2025, 07:14 PM