• 15 Posts
  • 9 Comments
Joined 5M ago
cake
Cake day: Jan 02, 2022

help-circle
rss
How to disable reading password timeout?
I know I can disable password aging with: ``` sudo visudo ``` And adding: ``` Defaults timestamp_timeout=-1 ``` But how can I disable timeout when reading passwords instead? To avoid this kind of error: ``` [sudo] password for user: sudo: timed out reading password sudo: a password is required -> exit status 1 ```
fedilink

Check for sudo access in bash script
Is this the correct way to check for sudo access? ``` has_sudo() { if [[ "$EUID" = 0 ]]; then exit 0 else sudo -k # make sure to ask for password on next sudo if sudo true; then exit 0 else exit 1 fi fi } load_zshenv_on_startup() { if has_sudo; then append_zshenv_to_global_files else link_zshenv_to_home_directory fi } ```
fedilink

I was thinking of asking “What are the aliases or functions that you find most useful?” in /c/Bash.



How can I evaluate a variable before appending with tee?
I need to evaluate this variables before appending this lines to a few files: ``` sudo tee -a /etc/profile /etc/zshenv /etc/zsh/zshenv &>/dev/null <<EOF export XDG_CONFIG_HOME="$SYNC"/config export XDG_CACHE_HOME="$HOME"/.cache export XDG_DATA_HOME="$HOME"/.local/share export XDG_STATE_HOME="$HOME"/.local/state export ZDOTDIR="$XDG_CONFIG_HOME"/zsh EOF ```
fedilink


Yeah I meant that. Wow I hadn’t even thought of grep which should have been the first that came to mind. Thanks.


This is the function defined by Oh My Zsh, I don’t quite understand it, so I won’t use it:

function _omz::reload {
  # Delete current completion cache
  command rm -f $_comp_dumpfile $OMZ_COMPDUMP

  # Old zsh versions don't have ZSH_ARGZERO
  local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
  # Check whether to run a login shell
  [[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
}


Sometimes when you copy a directory the folder permissions get messed up. I’m trying to make a function to fix the permissions so the files and folders don’t allow writing or executing to anyone other than yourself.


How to improve this fix permissions function efficiency?
How do I improve this function efficiency so that it only searches once instead of three times: ``` # Fixes permissions for files and directories in the given folder or the current folder fixperms() { find "${1:-.}" -type f -executable -exec chmod 744 {} \; find "${1:-.}" -type f ! -executable -exec chmod 644 {} \; find "${1:-.}" -type d -exec chmod 755 {} \; } ```
fedilink

How to clear zsh configuration?
I think it was `zsh -z` but I'm not sure. It's for doing this: ``` reload_zsh() { echo "Reload zsh" zsh -z [ -f $ZSHRC ] && source $ZSHRC } ```
fedilink

How to let every file know the absolute path of the root of a project and be able to change a folder path easily?
I want to let every file know the path of the root of a project. For example let's consider this the root: `/home/username/.config/project`. If I have a folder in the project and every file in the folder has a line like `ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"` (gets the absolute path of the parent directory) whenever I move the folder to another location I may have to change that line for every file in the folder. Is there a better option to let every file know the path of the project root?
fedilink

I’ve thought of creating a json where I indicate what parts have been executed successfully.


How to avoid part of a bash script from executing twice when re-running the script?
For example I have a function that appends to a file a few lines. But if something else fails in the script I wouldn't want to fix it and execute it again, and then have those lines duplicated.
fedilink

Small projects to practice TDD?
I want to make a website using TDD. But I want to read and practice with a couple of small projects first. I'll read it, and then try it myself and check my implementation with the repository. I'm looking for projects with good test coverage, of less than 5k lines, written in JavaScript, Python, go or Rust. Where can I find this kind of projects? Github advanced search doesn't have the ability to look for number of lines of code or test coverage. This is what I've found: **npm modules** usually have tests: - JavaScript, 1.8k lines, 77% coverage: https://github.com/jshint/fixmyjs **katas, exercises, challenges**: [exercism](https://github.com/exercism?q=&type=all&language=&sort=stargazers) has a repository for each language, with exercises and tests.
fedilink

I mean selenium for uploading to HeapOverflow.

Let’s write some high level pseudocode to make sure we are on the same page before I begin:

Download all question pages from StackOverflow.
Use beautiful soup to get each separate question, a link to the question, answers and their dates.
Add the link to the question.
Add the license depending of the date to each question and answer.
Use selenium to create a post in HeapOverflow with the question.

Mass import from StackOverflow to HeapOverflow.ml
> I’d be down for mass import as long as it’s done well. My idea is either do it with selenium, simulating the usage of a normal user on the website. In that case, every post would have my user as the creator and would generate a lot of spam in the front wall. Or it could be done directly to the database, but that would create bogus users that would be unavailable to use for anyone else. I think it would be better to do the later but with a reserved user that you create only for that purpose and has a descriptive name like "bot". Let me know your ideas.
fedilink

Actually, you were right, I hadn’t reloaded the configuration, and now that I have, the variables are not expanding in the single quotes.


It seems to be expanding correctly for me:

which et
et: aliased to VIM= VIMRUNTIME= nvim /home/ajr/cloud/config/dotfiles/tmux/tmux.conf

I’ve leaved it at this:

# Quick access to the configuration files
alias ez='${EDITOR} ${ZSHRC}'
alias eenv='${EDITOR} ${ZSHENV}'
alias ev='${EDITOR} ${MYVIMRC}'
alias et='${EDITOR} ${TMUXRC}'

[zsh] What is the proper way to define this aliases?
I have several ways of defining aliases mixed together and I want to make them all the same. But I don't even know why I've written them in different ways and now I don't know which to choose. I think `${ZDOTDIR:-$HOME}/.zshrc` is a bad idea. I should just define `$ZSHRC` somewhere and call it here, or I would have to change it in many places if I wanted to change the file location or name. But what about the rest, I have this in one place `'${=EDITOR} "$MYVIMRC"'` and this in another `"$EDITOR $TMUXRC"`, which are the same in my opinion. ``` # Quick access to the .zshrc file alias ez='${=EDITOR} ${ZDOTDIR:-$HOME}/.zshrc' alias zshrc='${=EDITOR} ${ZDOTDIR:-$HOME}/.zshrc' alias ev='${=EDITOR} "$MYVIMRC"' # edit vimrc alias vimrc='${=EDITOR} ${ZDOTDIR:-$HOME}/.zshrc' alias et="$EDITOR $TMUXRC" # edit tmux.conf alias tmuxrc="$EDITOR $TMUXRC" ```
fedilink

Complete javascript example videos?
I really liked this video. It isn't prepared, he just pauses the video when he has a bug. Any more videos like this for javascript? I'm going to try now to do the same by myself and see if I get it right.
fedilink