/r/commandline
This is for anything regarding the command line, in any operating system. All questions (including dumb ones), tips, and links to interesting programs/console applications you've found or made yourself are welcome. Linux / BSD / OSX / Windows CLI and TUI apps or questions or comments, we're happy to take them all!
-----------------------------
/ This is for anything
| regarding the command line, |
| in any operating system. All |
| questions (including dumb |
| ones), tips, and interesting |
| programs/console applications |
| you've found or made yourself |
| are welcome. Please read the |
| rules, and you're welcome to |
| flair your posts if you want |
\ to. / |
---|
\ ^__^
\ (OO)\_______
(__)\ )\/\
||----w |
|| ||
commandline@reddit ~ $ _
If you're asking for help, remember to help the community by stating what OS and version you're using, and if at all possible paste any commands you've tried and any errors or output that you've seen.
Related subreddits:
/r/commandline
My tool reduces the size of GeoJSON files by truncating latitude/longitude coordinates to the specified decimal places, eliminating unnecessary whitespace and (optionally) replacing the properties key's value with null/empty dictionary.
Check it out if you're interested!
Good evening. I am trying to get a MacOS terminal to output the date of the Monday of the current week in YYYYDDMM format.
That means if today is March 31 2024, or if today is April 2 2024, the output of the command would yield me "20240104" (April 1st 2024). The following week that would start on Sunday April 7 2024 through April 13 2024 should output "20240804" (April 8 2024).
And so on. Does anyone know a command or script that will do this? To me the first day of the week is Sunday if that matters for scripting purposes. Thank you in advance.
Edit: I made a mistake in the title. I want YYYYDDMM NOT YYYYMMDD.
Edit 2: This appears to be solved thanks to u/cd109876!
with units now I am starting to really be happy with the state of my calculator, assuming I don't have too many bugs https://github.com/bgkillas/kalc (sorry about bad name) would appreciate suggestions on what to do next.
This script makes API calls to OpenAI to generate text, images and speech to text in CLI.
GitHub : https://github.com/LordPax/cligpt
and vim plugin : https://github.com/LordPax/vim-cligpt
smenu started as a lightweight and flexible terminal menu generator, but quickly evolved into a powerful and versatile CLI selection tool for interactive or scripting use.
smenu makes it easy to navigate and select words from stdin or a file using a friendly text-based user interface. The selection is printed to stdout for further processing.
Tested on Linux and FreeBSD but should work on other Unix as well.
It is available here: https://github.com/p-gen/smenu
I'm have the following issue with my custom prompt bash prompt. When gitInfo
is return it has spaces in it and its causing the output of customPrompt
getting mangled due to bash splitting it on spaces. I've tried escaping them \
but it doesn't fix it.
I could just use another character and tr
it to space after the fact but I'd like to know the proper way to deal with. Googling just talks about using double quotes and escaping which I already tried.
function gitInfo(){
[ -d .git ] || return
BRANCH=$(git branch 2>/dev/null | grep -oP '(?<=^\*\s)(.*)')
if [[ ! -z "$BRANCH" ]]; then
ADDED=$(git status -s | awk 'BEGIN {c=0;} {if ($1 == "A") c+=1} END {print c}')
MODIFIED=$(git status -s | awk 'BEGIN {c=0;} {if ($1 == "M") c+=1} END {print c}')
DELETED=$(git status -s | awk 'BEGIN {c=0;} {if ($1 == "D") c+=1} END {print c}')
UNTRACKED=$(git status -s | awk 'BEGIN {c=0;} {if ($1 == "??") c+=1} END {print c}')
printf "(\uE0A0%s +%s ~%s -%s ?%s)" $BRANCH $ADDED $MODIFIED $DELETED $UNTRACKED;
fi;
}
function gitColor(){
GREEN="\e[1;32m"
RED="\e[1;31m"
[[ "$(git status --porcelain 2>/dev/null | wc -l)" -gt 0 ]] && printf $RED || printf $GREEN
}
function customPrompt(){
local ec="$?"
local RESET="\e[0m"
local FG_RED="\e[1;31m"
local FG_GREEN="\e[1;32m"
local FG_YELLOW="\e[1;93m"
local FG_BLUE="\e[1;34m"
local FG_PURPLE="\e[1;35m"
prompt=""┌""
prompt+="[$FG_YELLOW$(date -Is | cut -d + -f 1)$RESET]"
prompt+="[${FG_RED}$(whoami)${RESET}@${FG_BLUE}$(hostname)${RESET}]"
prompt+="[$FG_GREEN$(dirs -0)$RESET]"
prompt+="$(gitColor)$(gitInfo)$RESET"
prompt+="\n"
prompt+="└"
if [ $ec -eq 0 ]; then
prompt+="$FG_GREEN"
else
prompt+="$FG_RED"
fi
prompt+=">$RESET"
printf $prompt
return $ec
}
I was working in my email today on a flight. Once I got home and opened my computer, I watched all of my emails in my Inbox disappear. I’ve been using Neomutt for quite some time but the only way I know that I could have accidentally cleared the emails from my Inbox was if I held down ‘a’ to mark them to archive or ‘d’ to mark them to delete. But both of those actions prompt me for confirmation before moving the email to the respective folder.
I’m not sure what happened, but I cannot find the emails in any other folder. The archive, delete, and sent folders all appear intact. Any advice on how I might be able to recover these? Thanks.
I'm looking for a cli task manager for windows (not WSL, any native ones ). I'm aware about taskwarrior. But it is not on Windows, which is really unfortunate. Why windows ? Because of work.
Why not WSL ? Well actually, I tried taskwarrior on WSL and I was frustrated by WSL. Because it takes like forever to open up. Not just the first time, even after a while when I close a terminal and open another, it took like 4 mins to open. Earlier I used to open WSL first then use taskwarrior. After a while I just made alias as wsl task
but even then it took like 2-3 minutes to launch. It's not that application are slow on my machine, Infact, windows native cli tools run relatively very fast. Enough about WSL. But no WSL suggestions please
What I want from task manager.
Edit: I've looked for some task managers on GitHub, but couldn't find that would fulfill the above things. If you guys know any, please suggest. I'm ready to try.
Hello everyone! I was interested in making a simple yet useful project in C and came with belformat which is a library that helps you format your output with different styles and colors in your terminal.
If you ever wanted to format your output with pretty HTML-like syntax, you might be interested in using this library, because there are all ANSI default styles (bold, italic, underlined, strikethrough, dim, blinking, reversed and private), as well as support of different terminal-defined and user-defined colors.
If you're interested, you can take a look at it here: https://github.com/Artiom-Astashonak/belformat
P.S. It's my first project written in C and I would like you to share your opinions on how it came out. Thanks ;)
Cross platform command line tool to validate the syntax of all your configuration files.
Lots of changes in this release. Here are some highlights:
Every functional change was made by an open source contributor. Thanks to everyone who contributed!
https://github.com/Boeing/config-file-validator/releases/tag/v1.6.0
Anyone do anything like this before
In wsl, I use tabby access my linux environment and also to connect to remote hosts with SSH. I have tried also the Windows terminal, kitty, and so on. In the bash env, I use tmux.
But I am missing a feature which is file explorer that allows me to open the file, copy file with drag and drop, and so on. I want a file explorer that is integrated in the terminal emulator, and when I am connected to a SSH host, it shows me automatically the files in the remote host.
Which application do you suggest?
Hey hey,
i recently installed fzf and it seems amazingly useful. I'm using bash with a key-bindings.bash which is only slightly altered, to allow for ctrl-e to be used instead of alt-c . I will try to paste it below.
I would like to know how i could allow for fzf to pick up on dotfiles ("hidden files"), cause as of now they are not suggested when i do ctrl-t . I guess there is something with the call to find, that i need to tweak.
Related to this i would like to know if it's possible to maybe omit suggestions that come from inside .git directories.
# ____ ____
# / __/___ / __/
# / /_/_ / / /_
# / __/ / /_/ __/
# /_/ /___/_/ key-bindings.bash
#
# - $FZF_TMUX_OPTS
# - $FZF_CTRL_T_COMMAND
# - $FZF_CTRL_T_OPTS
# - $FZF_CTRL_R_OPTS
# - $FZF_ALT_C_COMMAND
# - $FZF_ALT_C_OPTS
# Key bindings
# ------------
__fzf_select__() {
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | cut -b3-"}"
eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" $(__fzfcmd) -m "$@" | while read -r item; do
printf '%q ' "$item"
done
echo
}
if [[ $- =~ i ]]; then
__fzfcmd() {
[[ -n "$TMUX_PANE" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "$FZF_TMUX_OPTS" ]]; } &&
echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"
}
fzf-file-widget() {
local selected="$(__fzf_select__)"
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
}
__fzf_cd__() {
local cmd dir
cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype
'proc' \\) -prune \
-o -type d -print 2> /dev/null | cut -b3-"}"
dir=$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcm
d) +m) && printf 'cd -- %q' "$dir"
}
__fzf_history__() {
local output
output=$(
builtin fc -lnr -2147483648 |
last_hist=$(HISTTIMEFORMAT='' builtin history 1) perl -n -l0 -e 'BEGIN { getc; $/ = "\n\t"; $HISTCMD = $ENV{last_hist} + 1 } s/^[ *]//; print
$HISTCMD - $. . "\t$_" if !$seen{$_}++' |
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort,ctrl-z:ignore $FZF_CT
RL_R_OPTS +m --read0" $(__fzfcmd) --query "$READLINE_LINE"
) || return
READLINE_LINE=${output#*$'\t'}
if [[ -z "$READLINE_POINT" ]]; then
echo "$READLINE_LINE"
else
READLINE_POINT=0x7fffffff
fi
}
# Required to refresh the prompt after fzf
bind -m emacs-standard '"\er": redraw-current-line'
bind -m vi-command '"\C-z": emacs-editing-mode'
bind -m vi-insert '"\C-z": emacs-editing-mode'
bind -m emacs-standard '"\C-z": vi-editing-mode'
if (( BASH_VERSINFO[0] < 4 )); then
# CTRL-T - Paste the selected file path into the command line
bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
bind -m vi-command '"\C-t": "\C-z\C-t\C-z"'
bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"'
# CTRL-R - Paste the selected command from history into the command line
bind -m emacs-standard '"\C-r": "\C-e \C-u\C-y\ey\C-u"$(__fzf_history__)"\e\C-e\er"'
bind -m vi-command '"\C-r": "\C-z\C-r\C-z"'
bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"'
else
# CTRL-T - Paste the selected file path into the command line
bind -m emacs-standard -x '"\C-t": fzf-file-widget'
bind -m vi-command -x '"\C-t": fzf-file-widget'
bind -m vi-insert -x '"\C-t": fzf-file-widget'
# CTRL-R - Paste the selected command from history into the command line
bind -m emacs-standard -x '"\C-r": __fzf_history__'
bind -m vi-command -x '"\C-r": __fzf_history__'
bind -m vi-insert -x '"\C-r": __fzf_history__'
fi
# ALT-C - cd into the selected directory
bind -m emacs-standard '"\C-e": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d"'
bind -m vi-command '"\ec": "\C-z\ec\C-z"'
bind -m vi-insert '"\ec": "\C-z\ec\C-z"'
fi
Hello everybody,
I published yesterday A Practical Guide to fzf: Building a Git Explorer. I love fzf to build custom interfaces to simplify some of my workflow; the goal of this article is to show fzf advanced features and how we can use them to build interfaces for Git.
More specifically, we build three different interfaces in this article:
These fzf interfaces allow us to add files, reset files and commits, checkout or rebase branches, cherry-pick commits, and more.
Hope you like it! I'm always happy to get feedback, from extremely positive to absolutely roasty.
I wrote this because I wanted a to-do list CLI with an interactive panel, which allows me to navigate through tasks, delete them etc. by just pressing keys, instead of typing commands like todo list
or todo done xxx
every time. I searched for such programs but could not find one. More new features are on the way. Please have a look and tell me if I should invest a bit more time in this small CLI program :) Thank you!
I'm currently writing one in rust based on some things I found lacking, now I'm looking to see if there are other painpoints others have with the current selection!