terminal_tracker package

Submodules

terminal_tracker.export module

class terminal_tracker.export.Export(file, timeframe, shell)[source]

Bases: object

This class helps in exporting the history file in a better usable format

timeframe

whether time values are present in the history file

Type:

bool

shell

“zsh” or “bash”

Type:

str

df
Columns:

Command(str), Main Command (str), Arguments (str), Tags (str)

Optional Columns:

Time (str), Pretty Time (datetime.datetime)

Type:

pandas.DataFrame

tag

processed for efficient searching of tags

Type:

Tags

time

processed for efficient searching of day

Type:

TimeAnalysis

csv(filename)[source]

Converts dataframe to csv file of given name

excel(filename)[source]

Converts dataframe to excel file of given name

html(filename)[source]

Converts dataframe to html file of given name, adds the extension “.html” if not present in the filename

pick(category, value)[source]

Sorts the commands in the dataframe by a specified category and value, and stores the sorted dataframe in the same “df” attribute. This method should be used before exporting the dataframe.

Parameters:
  • category (str) – The category to sort by. Must be one of “tag” or “time”.

  • value (str) – The value to filter by. If category is “tag”, this should be a tag name. If category is “time”, this should be a date string in the format “YYYY-MM-DD”.

Raises:
  • ValueError – If category is not one of “tag” or “time”.

  • Exception – If category is “time”, but the file doesnot have time values

sort_by(way)[source]

Sorts the commands in the dataframe using various methods and stores the sorted commands in the same “df” attribute. This method should be used before exporting the dataframe.

Parameters:

way (str) – The method to use for sorting. Must be one of the following:, “Start Command”: Sort by the start command of each command. “Full Command”: Sort by the full command. “Start Frequency”: Keep only unique full commands with their frequency. “Full Frequency”: Keep only unique start commands with their frequency. “Collate Main”: Group the commands by their start command.

Raises:

ValueError – If way is not one of “Start Command”, “Full Command”, “Start Frequency”, “Full Frequency”, or “Collate Main”.

terminal_tracker.frequency module

class terminal_tracker.frequency.FrequencyFile(file, timeframe=False, shell='zsh')[source]

Bases: object

This class helps to calculate the frequencies of the commands

file

path to the history file

Type:

str

timeframe

whether time values are present in the history file

Type:

bool

shell

“zsh” or “bash”

Type:

str

full_command_freq

Frequency of each “full” command

Type:

dic

start_command_freq

Frequency of each “start” command

Type:

dic

full_command_freq

Frequency of each “full” command in order of decreasing frequency

Type:

list

start_command_freq

Frequency of each “start” command in order of decreasing frequency

Type:

dic

Todo

  • Only works with files without timeframe and tags

calc_full_command_freq()[source]

Calculates the frequency of each “full” command

Returns:

Frequency of each “full” command

Return type:

dic

calc_start_command_freq()[source]

Calculates the frequency of each “start” command

Returns:

Frequency of each “start” command

Return type:

dic

find_most_frequent()[source]

Finds the most frequent “full” command

Returns:

most frequent “full” command

Return type:

str

find_most_frequent_start()[source]

Finds the most frequent “start” command

Returns:

most frequent “start” command

Return type:

str

find_top_full(t=10)[source]

Finds the top “t” most frequent “full” command

Parameters:

t (int) – Number of commands

Returns:

top “t” most frequent “full” command

Return type:

list

find_top_start(t=10)[source]

Finds the top “t” most frequent “start” command

Parameters:

t (int) – Number of commands

Returns:

top “t” most frequent “start” command

Return type:

list

print_top(type='full', N=10)[source]

Helper function to print the most frequent commands

Parameters:
  • N (int) – Number of commands

  • type (str) – “full” or “start”

recommend_alias(weight_freq=0.5, weight_len=0.5)[source]

Recommends functions that should have an alias based on length and frequency of command usage

Parameters:
  • weight_freq (float) – Weight given to frequency of command

  • weight_len (float) – Weight given to lenght of command

terminal_tracker.preprocess module

class terminal_tracker.preprocess.Preprocessing(file, timeframe=False, shell='zsh')[source]

Bases: object

This class helps in preprocessing the history files

file

path to the history file

Type:

str

timeframe

whether time values are present in the history file

Type:

bool

shell

“zsh” or “bash”

Type:

str

df
Columns:

Command(str), Main Command (str), Arguments (str), Tags (str)

Optional Columns:

Time (str), Pretty Time (datetime.datetime)

Type:

pandas.DataFrame

terminal_tracker.searching module

class terminal_tracker.searching.SearchFile(file)[source]

Bases: object

This is a simple search class .. attribute:: file

path to the history file

type:

str

Todo

  • Move to using the Preprocessing class

find(a)[source]

Finds all commands containing the word

Parameters:

a (str) – word

Returns:

commands containing the word

Return type:

list

latest(a)[source]

Finds the latest command containing the word

Parameters:

a (str) – word

Returns:

the latest command containing the word

Return type:

str

latest_iterator(a)[source]

Iterator that finds the latest commands containing the word

Parameters:

a (str) – word

Yields:

str – commands

using_latest_iterator(a)[source]

Printing the latest commands containing the word

Parameters:

a (str) – word

terminal_tracker.tag module

class terminal_tracker.tag.Tags(file, timeframe, shell)[source]

Bases: object

This class helps to search commands with certain tags

prep

Preprocessing the file using the Preprocessing class

Type:

Preprocessing

df

Preprocessed dataframe Columns:

Command(str), Main Command (str), Arguments (str), Tags (str)

Optional Columns:

Time (str), Pretty Time (datetime.datetime)

Type:

pandas.DataFrame

search(a)[source]

Searches for commands with tag “a” in history file and get only the commands

Parameters:

a (str) – Tag

Returns:

Commands containing the tag “a”

Return type:

list

search_df(a)[source]

Searches for commands with tag “a” in history file and get the entire information

Parameters:

a (str) – Tag

Returns:

Dataframe with only rows with commands containing the tag

Return type:

pandas.Dataframe

terminal_tracker.timeanalysis module

class terminal_tracker.timeanalysis.TimeAnalysis(file, shell)[source]

Bases: object

This class helps to search commands with certain tags

prep

Preprocessing the file using the Preprocessing class

Type:

Preprocessing

df

Preprocessed dataframe Columns:

Command(str), Main Command (str), Arguments (str), Tags (str), Time (str), Pretty Time (datetime.datetime)

Type:

pandas.DataFrame

Todo

  • reject files with no timeframe

search_day(day)[source]

Finds commands that were executed on the given day

Parameters:

day (str) – Day in YYYY-MM-DD format

Returns:

Dataframe containing rows that were executed on the day

Return type:

pandas.DataFrame

Module contents